Created
August 10, 2011 23:55
-
-
Save kmizu/1138598 to your computer and use it in GitHub Desktop.
Emulation of Listing Six in http://www.cs.tut.fi/lintula/manual/modula3/modula-3/html/partial-rev/index.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
trait Association { | |
type Item <: AbstractItem | |
trait AbstractItem { | |
def memberOf(): Group | |
} | |
type Group <: AbstractGroup | |
trait AbstractGroup { | |
def addItem(item: Item) | |
def removeItem(item: Item) | |
def items(): List[Item] | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
object AssociationModule extends Association { | |
type Item = ConcreteItem | |
class ConcreteItem extends AbstractItem { | |
var group: Group = _ | |
override def memberOf(): Group = group | |
} | |
type Group = ConcreteGroup | |
class ConcreteGroup extends AbstractGroup { | |
var itemSet = Set[Item]() | |
override def addItem(item: Item) = { | |
itemSet += item | |
} | |
override def removeItem(item: Item) = { | |
itemSet -= item | |
} | |
override def items() = itemSet.toList | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment