Overview of Commonly Used UML Symbols

This article explains some of the commonly used UML symbols that we need to understand to design for working on the class level design patterns. Besides association, aggregation and composition there are other UML designs and OOP concepts that we need to be familiar with. Since I myself sometimes become confused about the symbols I thought to come up with this article to have a nice handy reference.

In the following table I have mentioned some of the commonly used symbols that explains their use with examples:

UML

1. Inheritance

Inheritance is one of the key concepts of the OOP in which we can inherit the public properties and methods of the base class into the derived class. In the code snippet below I have mentioned an inheritance example where the Employee (A as per our UML notation above) class is being derived from by the Manager (B) class.

  1. public class Employee {  
  2.     //Class Implementation  
  3. }  
  4.   
  5. public class Manager: Employee {  
  6.     //Class Implementation  
  7. }  
2. Realization

This is the concept using which a derived class implements the virtual functions of the base class, usually an interface or an abstract class. All the methods or properties that are abstract in the base class are implemented in the derived class that is usually non-abstract.
  1. public interface IEmployee {  
  2.     void GetAccess();  
  3.     //other abstract implementation  
  4. }  
  5.   
  6. public class Manager: IEmployee {  
  7.     //Class Implementation  
  8.     #region IEmployee Members  
  9.   
  10.     public void GetAccess() {  
  11.         //implementation of the method  
  12.     }  
  13.  
  14.     #endregion  
  15. }  
3. Association

This is the kind of the design in which two classes taking part in the design are associated with each other in one or another way. Both of these classes can exist independently and their lifetime is not dependent on another object.

As an example take the case of the following code snippet that has two classes that are using each other's functionality.
  1. public class Manager {  
  2.     public void AssignProject(SoftwareEngineer engineer) {  
  3.         engineer.Project = "Designing Project";  
  4.     }  
  5.   
  6.     public void LeaveAppliedBy(SoftwareEngineer engineer) {  
  7.         //Track the leaves applied by all the employees  
  8.     }  
  9. }  
  10.   
  11. public class SoftwareEngineer {  
  12.     public string Project {  
  13.         get;  
  14.         set;  
  15.     }  
  16.   
  17.     public void AskForLeave(Manager manager) {  
  18.         manager.LeaveAppliedBy(this);  
  19.     }  
  20. }  
And in the main class we can use the two classes as shown.
  1. static void Main(string[] args) {  
  2.     Manager manager = new Manager();  
  3.     SoftwareEngineer se = new SoftwareEngineer();  
  4.   
  5.     manager.AssignProject(se); //manager assigns a project to the software //engineer  
  6.     se.AskForLeave(manager); //SE asks for leaves from manager  
  7. }  
As we can see from the preceding example, the two classes are using each other's functionality but that is not the only case. These two classes that can exist independently and work accordingly for themselves as per their functionality.

4. Association (one way)

The preceding scenario is not the only case of association. The other scenario is the one-way scenario in which only one of the classes participating in the design knows about the other, but the reverse is not true. In the code snippet shown below, the HR class can call and access the Employee's methods.
  1. public class HR {  
  2.     private IList < Employee > listOfEmployees = new List < Employee > ();  
  3.     public void AddEmployeeToOrg(Employee emp) {  
  4.         if (emp != null) {  
  5.             emp.AddEmployeeToPayroll();  
  6.             listOfEmployees.Add(emp);  
  7.         }  
  8.     }  
  9. }  
  10.   
  11. public class Employee {  
  12.     public string Name {  
  13.         get;  
  14.         set;  
  15.     }  
  16.     public void AddEmployeeToPayroll() {  
  17.         //some formalities which employee need to do to be part of the organization  
  18.     }  
  19. }  
5. Aggregation

This is an OOP concept in which the container class (A) maintains a has-a relationship with the containee class (B) in the UML diagram shown above, but the containee class can also be sustained even without the container class. In this case I want to take an example of the two classes, Employee and Address.
  1. public class Employee {  
  2.     public string Name {  
  3.         get;  
  4.         set;  
  5.     }  
  6.     public Address Address {  
  7.         get;  
  8.         set;  
  9.     }  
  10.   
  11.     public Employee(string name, Address add) {  
  12.         this.Name = name;  
  13.         this.Address = add;  
  14.     }  
  15. }  
  16.   
  17. public class Address {  
  18.     public string HouseNumber {  
  19.         get;  
  20.         set;  
  21.     }  
  22.     public string Street {  
  23.         get;  
  24.         set;  
  25.     }  
  26. }  
  27.   
  28.   
  29. static void Main(string[] args) {  
  30.     Address add = new Address() {  
  31.         HouseNumber = "204", Street = "Main Street"  
  32.     };  
  33.     Employee emp = new Employee("Vikram", add);  
  34. }  
As we can see from the preceding code snippet Address and Employee are two different enititioes and Employee has an Address and the Address can exist even without an Employee. Some Students can also have a has-an address also.

6. Composition

Composition is a specialized form of aggregation and it can be sometimes called a “Death” relationship. Since the entities taking part in this relationship cannot exist independently, carrying forward the same analogy I used in my previous examples, I want to cite one more example. Here in this example my Organization (A) entity contains a CEO and the Ilist<Employee> entities and both of these enities cannot exist independently without an organization class. And once the organization class is destroyed both of these classes are also destroyed.
  1. public class CEO {  
  2.     //CEO implementation   
  3. }  
  4.   
  5. public class Organization {  
  6.     public List < Employee > Employees {  
  7.         get;  
  8.         set;  
  9.     }  
  10.     public CEO CEO {  
  11.         get;  
  12.         set;  
  13.     }  
  14.   
  15.     public void AddEmployee(Employee emp) {  
  16.         if (emp != null) Employees.Add(emp);  
  17.     }  
  18.   
  19. }  

 

Up Next
    Ebook Download
    View all
    Learn
    View all