Understanding Association, Aggregation, Composition And Dependency Relationship With UML Diagram

Tools used to create  the diagram:
To understand more about the  nomnoml tool and UML representation, please refer to this UML Representation article.
 

Association

 
It represents the relationship between two objects, which have their own lifecycle and  no owner.
 
Example
 
Consider that Student and Teacher have objects. Here multiple students can associate with a single teacher and a single student can associate with multiple teachers. There is no ownership between these two objects.
 
Copy the below code in http://www.nomnoml.com/
  1. [Student]<->[Teacher]  

Aggregation

 
It represents the relationship of objects with their owners, like one object is the whole part or a part of another object
 
Example
 
Consider Department and Teacher have objects. Here a teacher belongs to muliple departments or is part of multiple departments. But when we delete, the Department Teacher object will not be destroyed.
 
Copy the below code in http://www.nomnoml.com/
  1. [Teacher]-o[Department]  

Composition

 
It represents the relationship of objects with parent/child relationship; i.e., child object is dependent on parent object
 
Example
 
A car has exactly one carburetor, and a carburetor is a part of one car. Carburetors cannot exist as separate parts, detached from a specific car.
 
Copy the below code in http://www.nomnoml.com/ 
  1. [Carborator]-+[Car]  

Dependency

 
It represents the relationship of objects where one object is dependent on another object.
 
Example
 
Client is dependent on server in web applications.
 
Copy the below code in http://www.nomnoml.com/  
  1. [Client]-->[Service]  
Scripts to draw UML in Nomnoml open source tool:
 
Association types
 
-         association
->       association
<->     association
-->      dependency
<-->    dependency
-:>       generalization
<:-       generalization
--:>      implementation
<:--      implementation
+-        composition
+->      composition
o-        aggregation
o->      aggregation
--        note
-/-       hidden
 
Connect with me in GitHub:
 
 

Conclusion 

 
In this article, we learned about Association, Aggregation, Composition and Dependency relationships with UML diagrams.
Next Recommended Reading UML Representation With Scripting