Skip to main content

UML Class Diagram Relationships

Below are the types of relationships in UML:


1. Inheritance(is a) / Generalization: Indicates that source type inherits from the target type.


2. Interface Realization: Indicates that source type realizes the target interface.


3. Association: Represents a general relationship between instances of the classes.
e.g.

  1. An employee can be associated with multiple with multiple projects where as a project can have more than one employee.
  2. A Teacher is associated with multiple students. 



4. Directed Association:  Directed association is related to direction of flow with in association classes.
In Directed association, the flow is directed. The association from one class to another class flows in single direction only.
e.g: A server can process requests of a client. This flow is unidirectional, that flows from server to client only. Hence a directed association relationship can be present within servers and clients of a system.

Server has access to Client but client doesn't have access to Server.



5. Aggregation: Indicates that the object at the end with diamond shape contains references to the object at the other end. If it contains that object exclusively, use a composition shape instead.

  • It is a type of Association.
  • An object of one class can own or access object of another class.
  • In Aggregation relationship dependent object remains in the scope even when the source object is destroyed.
  • Aggregation is considered as a weak type of Association.
  • e.g: 
    • A car needs a wheel to function correctly, but a wheel doesn't always need a car. It can also be used with the bike, bicycle or any other vehicle but not a particular car. Here the wheel object is meaningful even without a car object. Such type of relationship is called an Aggregate relationship.
    • A car needs a wheel but doesn't always require the same wheel . A car can function adequately with another wheel as well.
6. Dependency(Uses): Indicates that source type depends on the target type.


7. Composition(has a): Indicates that the source type has parts of the target type.

  • Composition is a sub type of Aggregation.
  • It is a two association between the objects.
  • It is a whole or part relationship.
  • If a composite is deleted all other parts associated with it are deleted.
  • Composition is considered as a strong type of Association.
  • e.g: The folder contains many files, while each file has exactly one folder parent. If a folder is deleted all contained files in the folder are also deleted

Association vs Aggregation vs Composition:

  • Aggregation and Composition are subset of association meaning they are specific cases of association.
  • In both Aggregation and Composition object of one class owns object of another class.
  • Aggregation implies a relationship where child can exist independent of parent.
    • e.g: Class (Parent) and Student(Child). Delete the class and students still exist.
    • e.g: Car(Parent) and Engine(child), Wheel(child). All three can exist independent of each other.
  • Composition implies a relationship where the child cannot be exist independent of parent.
    • e.g: House(Parent) and Room(Child). Room doesn't exist separate to a house.
    • e.g: Person(Head) and head(child), hand(child), leg(child). On Deleting person , there is no use of head, hand and leg.
    • e.g: Customer and his address


References: 



-Mayank


Comments

Popular posts from this blog

15404 error in SQL not able to create new DB diagram

In SQL Server Management Studio do the following: Right Click on your database, choose properties Go to the Options Page In the Drop down at right labeled "Compatibility Level" choose "SQL Server 2005(90)" 3-1. choose "SQL Server 2008" if you receive a comparability error. Go to the Files Page Enter "sa" in the owner textbox. 5-1 or click on the ellipses(...) and choose a rightful owner. Hit OK after doing this, You will now be able to access the Database Diagrams.

How to check if JWT Token is Tampered ?

JWT Tokens has three parts: Header Pay Load Signature Header includes the encryption algorithm and token type. e.g: {    "alg" : "HS256",    "typ" : "JWT" } Signature is created using base64url encoding the header and payload and concatenating them with a period(.) as a seperator. Take the signature of the token and decode it from base64, take the encryption algorithm from the header and generate the signature for the base64 encoded header + '.' + base64 encoded payload. If the signature received and calculated are matching then nobody has tampered the JWT. - Mayank Gupta

Design Patterns : Abstract Factory

Abstract Factory is a kind of Structural Design Pattern. Solves the problem of creating instances of entire product families without specifying their concrete class. Frequency of use: 5/5 (High) Intent: Provides an interface for creating families of related or dependent objects without specifying their concrete classes. The new operator is considered harmful Problem: Solution: Explicitly declare interfaces for each distinct product of the product family Make all variants of that product follow those interfaces Create an abstract factory which returns abstract product type represented by the interface UML Class Diagram: Code: using System; namespace AbstractFactory { class Program { static void Main(string[] args) { Console.WriteLine("This is Abstract Factory"); Console.ReadLine(); } } #region FamilyOfProducts abstract class Button { public abstract void Pain...