Using Aggregation in Inheritance

56 views Asked by At

I want to create an application for creating graphical documents, each document consists of several geometric shapes (Ball, Brick, Cylinder, Cube).

So I created two diagrams for my application, as shown in this picture : enter image description here

I want to know which diagram is better and why ? and what are the disadvantages and the advantages of both approaches.

2

There are 2 answers

0
Jim L. On

As Thomas says, it depends, but the right diagram has the potential to be more specific. That diagram opens the door to expressing existential quantification, which is to say that there must be some number of Cubes in a Document, for example. If you don't care to express that, the left diagram is clearly more expressive with fewer symbols.

0
qwerty_so On

Of course it depends on the requirements. But from a neutral standpoint the left one is definitely the better one since it has a better perspective for GraphicDocument. You don't need to know about the form of the elements only that they are shapes. So you can easily extend it without having to change GraphicDocument.

In other words: the left is loosely coupled while the right one is tightly coupled.