Rosetta Example: Constrained genericity
For details see http://rosettacode.org/wiki/Constrained_genericity
Define the two classes Eatable and Fish. Eatable is a class
for all eatable things, a Fish is a subclass ant therefore
eatable.
A FoodBax may only contain eatable items. Therefore with we define
items as a property of type Eatable" which has a multiplicity of
+0..n (might contain 0 to n eatable items). Furthermore, we define
items as incremental, such we can add / remove items with item
add or item remove.
Demonstrating the behavior in a shell:
Create two fishes, Wanda and Nemo:
Create a Foodbox and add the two fishes:
Return the print string of the contents: