How can I implement a strong containment relationship of uml. Also called composition.
To give an example in Scale: I have a class component, which may contain zero or more Interface:
class Component (name: String, description: String, Interaction: Set[Interface])
and then I have my class Interface:
class Interface(name: String, description: String)
What are the constraints that should be respected containment?
- If I enter an interface in a component, this interface cannot be placed inside other Component.
- If I delete a Component must also delete all of its interface.
There are other constraints to be enforced a containment?
How do I implement the first constraint:
I thought I'd add a field to the class Interface called signComp of type Component and put constraints on the set method Interaction of Component.
For example:
For each Interface that must be added to the Component, if the interface has signComp to null then insert the Interface and sets signComp with the Component current otherwise cancel the assignment.
This is a successful implementation? Or are there other ways.