Unified Modeling Language (UML) | Class Diagrams

What is UML?
It is the general purpose modeling language used to visualize the system. It is a graphical language that is standard to the software industry for specifying, visualizing, constructing and documenting the artifacts of the software systems, as well as for business modeling.

Benefits of UML:

  • Simplifies complex software design, can also implement OOPs like concept which is widely used.
  • It reduces thousands of words of explanation in a few graphical diagrams that may reduce time consumption to understand.
  • It makes communication more clear and real.
  • It helps to acquire the entire system in a view.
  • It becomes very much easy for the software programmer to implement the actual demand once they have the clear picture of the problem.

Types of UML: The UML diagrams are divided into two parts: Structural UML diagrams and Behavioral UML diagrams which are listed below:

  1. Structural UML diagrams
    • Class diagram
    • Package diagram
    • Object diagram
    • Component diagram
    • Composite structure diagram
    • Deployment diagram
  2. Behavioral UML diagrams
    • Activity diagram
    • Sequence diagram
    • Use case diagram
    • State diagram
    • Communication diagram
    • Interaction overview diagram
    • Timing diagram

UML class diagrams: Class diagrams are the main building blocks of every object oriented methods. The class diagram can be used to show the classes, relationships, interface, association, and collaboration. UML is standardized in class diagrams. Since classes are the building block of an application that is based on OOPs, so as the class diagram has appropriate structure to represent the classes, inheritance, relationships, and everything that OOPs have in its context. It describes various kinds of objects and the static relationship in between them.
The main purpose to use class diagrams are:

  • This is the only UML which can appropriately depict various aspects of OOPs concept.
  • Proper design and analysis of application can be faster and efficient.
  • It is base for deployment and component diagram.

There are several software available which can be used online and offline to draw these diagrams Like Edraw max, lucid chart etc. There are several points to be kept in focus while drawing the class diagram. These can be said as its syntax:



  • Each class is represented by a rectangle having a subdivision of three compartments name, attributes and operation.
  • There are three types of modifiers which are used to decide the visibility of attributes and operations.
    • + is used for public visibility(for everyone)
    • # is used for protected visibility (for friend and derived)
    • – is used for private visibility (for only me)

Below is the example of Animal class (parent) having two child class as dog and cat both have object d1, c1 inheriting properties of the parent class.

filter_none

edit
close

play_arrow

link
brightness_4
code

import java.io.*;
  
class GFG {
    public static void main(String[] args)
    {
        dog d1 = new dog();
        d1.bark();
        d1.run();
        cat c1 = new cat();
        c1.meww();
    }
}
  
class Animal {
    public void run()
    {
        String name;
        String colour;
  
        System.out.println("animal is running");
    }
}
  
class dog extends Animal {
    public void bark()
    {
        System.out.println("wooh!wooh! dog is barking");
    }
    public void run()
    {
        System.out.println("dog is running");
    }
}
  
class cat extends Animal {
    public void meww()
    {
        System.out.println("meww! meww!");
    }
}

chevron_right


Process to design class diagram: In Edraw max (or any other platform where class diagrams can be drawn) follow the steps:

  • Open a blank document in the class diagram section.
  • From the library select the class diagram and click on create option.
  • Prepare the model of the class in the opened template page.
  • After editing according to requirement save it.

There are several diagram components which can be efficiently used while making/editing the model. These are as follows:

  • Class { name, attribute, method}
  • Objects
  • Interface
  • Relationships {inheritance, association, generalization}
  • Associations {bidirectional, unidirectional}

Class diagrams are one of the most widely used diagrams in the fields of software engineering as well as businesses modelling.



My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.




Article Tags :
Practice Tags :


2


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.