Composition in OOP with Visual Basic .NET

To identify the composition relationship between two classes you should have association and aggregation between those two classes

In the following example Class B is part of Class A and also this has the association. So now you have association and aggregation

Class A is the whole

Class B is the part

Lets say, we have the  lifecycle of the part class (Class B) depends on the that of the whole class (Class A). Then we can tell that there is composition between these two classes

In other words existence of Class B depends on existence of Class A

You can understand composition in real world thinking of Company and Department. Department is a part of the Company and there is no department without company

This is the UML model diagram in Visual Studio .NET

In this diagram you have filled diamond next to the whole (Company)

Leave a Reply

Your email address will not be published. Required fields are marked *