Skip to content

Instantly share code, notes, and snippets.

@kmizu
Created August 10, 2011 23:55
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kmizu/1138598 to your computer and use it in GitHub Desktop.
Save kmizu/1138598 to your computer and use it in GitHub Desktop.
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]
}
}
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