DEV Community

Prashant Mishra
Prashant Mishra

Posted on • Edited on

Class diagram

Class diagram is one of the UML (Unified Modelling diagram) in software engineering.

In the class diagram the classes have various relationships with other/related or dependent classes to function properly

Relationship Type Symbol Usage
Generalization Is-a(Inheritance) inheritance Car,Truck,Bike are Vehicle
Realization Implementation interface IPrinter is an interface which is implemented by HpPrinter and CanonPrinter (Overriding the methods of Iprinter interface)
Association bi-directional (between parent and child) association Library has many book and a Book belongs to a specific library ( here Library can be parent and Book can be child
Directed Association One class is associated with another dirAssociation Teacher class has an associated relation with the Class Course that Teacher teaches
Aggregation Whole-part relationship aggregation It is specialized form of association, where one class(whole) is composed of another class(part), but the part class can exists independently e.g CompanyABC(Whole) composed of Empoyee(Part), but if The Company ceases to exist the Employee can still survive
Composition Whole-part relationship composition It is more stronger form of aggregation, where part can not exist without the Whole e.g. DigitalContactPage(Whole) has Contact(Part), but if the DigitalContactPage is deled then the Contact will be lost forever
Dependency client-supplier relationship dependency Temporary and weaker(relationship is not long-lived.); the client class depends on the supplier class but does not "own" it. e.g.Person class depends on Book class to read it, but the Book class is not dependent on Person class, and use of Book class is done as soon as the Person class is done using it
Usage(dependency) client-supplier relationship usageDependency A usage dependency relationship in a UML class diagram indicates that one class (the client) utilizes or depends on another class (the supplier) to perform certain tasks or access certain functionality. e.g.Consider a scenario where a “Car” class depends on a “FuelTank” class to manage fuel consumption.

Note: while choosing relationship between classes there could be various ways to pick which relationship will best describe the relation, it can vary from context to context as and when you practice you will be able to get hold of these relationships

association

Class diagram of class Car:

car
It is composed of class name, attributes, and methods

Visible notations:

Symbol Use
+ for public (visible to all classes)
- for private (visible only within the class)
# for protected (visible to subclasses)
~ for package or default visibility (visible to classes in the same package)

Top comments (0)