Renaud is Not Bill Gates
Renaud is Not Bill Gates

Reputation: 2074

Using Aggregation in Inheritance

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.

Upvotes: 2

Views: 59

Answers (2)

Jim L.
Jim L.

Reputation: 6529

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.

Upvotes: 0

qwerty_so
qwerty_so

Reputation: 36295

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.

Upvotes: 1

Related Questions