The following is a personal attempt at implementing the Composite design pattern in Scala. Observation
is abstract...
class CompositeObservation(obss: Observation*) extends Observation {
val elements: MutableList[Observation] = new MutableList[Observation]()
elements ++ obss
def hasElement(o: Observation): Boolean = elements.contains(o);
}
hasElement
fails to return if an element is contained in the composite. Questions:
- Am I misinterpreting the ++ operator? The Observation*?
- What is the most ideomatic way to implement this pattern in Scala?