Learn how to design the Class Diagram

Tram Ho

In a project, the organization of the code as well as the clean code is very important, if the design of reasonable and clear classes will help a lot for expansion and maintenance later. To do this we need to have a truly reasonable Class Diagram design. So what is Class Diagram, let’s find out.

Definition of Class Diagram

  • The class diagram describes the types of objects in the system and the various types of relationships that exist between them.
  • As a modeling technique exists in all object-oriented development methods.
  • Charts are most commonly used in UML and are closest to the programmers.
  • Help programmers communicate with each other and understand each other’s ideas.

The basic properties of class diagrams

  • Class name
  • Attribute (field, property)
  • Operation (method, function)

For example, declare the name, attribute, operation and return type of a class:

Access Modifier in class diagram

  • Used to specify the scope of access for attributes and operations of a class (authorize other classes to use attributes and operations of this class).
  • 4 selectable access ranges
    • Private (-): Customize yourself objects created from this class can use.
    • Public (+): Any object can use.
    • Protected (#): Only objects created from this class and classes inheriting from this class can be used.
    • Package / Default: Objects created from classes in the same package class can use them.

Relationship in class diagram

  • Used to show each relationship between objects created from 1 class with objects created from other classes in the class diagram.
  • 4 types of Relationship:
    • Inheritance: A class inherits from another class.
    • Association: 2 classes are related but do not specify a relationship.
    • Composition: If object created from lass A loses object from class B will be lost.
    • Agreegation: A class object is related to the other classB object, but if object B loses then object A is still normal.

Multiplicity in class diagram

  • Used to show the number relationship between objects created from classes in the class diagram
    • 0 … 1: 0 or 1
    • n: Required n
    • 0 … *: 0 or more
    • 1 … *: 1 or more
    • m … n: there is a minimum of m and a maximum of n


  • The design of class diagrams is essential that a professional programmer must have.
  • We hope your suggestions to improve themselves in the next article ❤️
Share the news now

Source : Viblo