If I have a class called Location
and a class called Maze
which has a field which is an array of 'Location' objects as shown below then is this a composition relationship because 'Maze' typically has more than one 'Location' object?
Is this a correct relationship between the 2 classes? or is composition only if it has one object of another class?
Also say if Maze
has a constructor which takes an parameter of type Space
such as: public Maze(Space space){}
then what would be the relationship between Maze
and Space
?
A good question to ask about composition is "If the parent is destroyed, is the child destroyed". In composition (as opposed to aggregation), the lifecycles are intertwined. In this case, if maze is destroyed, all the locations should be destroyed as well, making it clearly a composition relationship.