In this post we are going to learn about “How to draw Class Diagram”. Before this you need to know the basics about class diagrams and for that read out last post:
UML – WHAT IS THE PURPOSE OF CLASS DIAGRAMS
Let’s start and learn how to draw a class diagram.
How to Draw a Class Diagram:
- Class diagram is basically a graphical representation of the static view of the system and represents different aspects of the application.
- A collection of class diagrams represent the whole system.
So, a system might be having some hundreds of classes or thousands of classes and that’s why the class diagram might be a too big one to interpret and accordingly we’ll be developing our software or application.
Important Points to remember while drawing a Class diagram:
- The name of the class diagram should be meaningful to describe the aspect of the system.
That means, always the nomenclature of the class diagram should be purposeful. So, that, from the class name we should get to know – what is the purpose of the class.
- Each element and their relationships should be identified in advance.
That means, each and every element and what are the respective relationship between them, they are to be described in advance in a very descriptive way.
- Responsibility (i.e., attributes and methods) of each class should be clearly identified.
As, we are having the list of attributes holding some values and while defining those attributes, their respective constraints and their data types must be declared explicitly. The methods whether they’ll be coming under the Private scope or say public scope, they are to be mentioned properly with their respective input and output arguments. The name of the methods must be also purposeful.
So, all you have to remember is a purposeful name for the class, purposeful name for the attributes, purposeful name for the methods. This is a good programmers practice and that should be followed for defining with all details.
- For each class minimum number of properties should be specified, as unnecessary properties will make the diagram too much complicated.
So, we should mention only those properties which are essential.
- Use notes wherever required to describe some aspect of the diagram. At the end of the drawing it should be understandable to the developer or the respective coder.
That means, we can put some notes. With the help of notes we can describe the purpose of the class along with some other detailing.
Also, we can write about scope of method and can write a sample code, sample algorithm or the part of the code to give the guidance or idea to the coder or the developer to develop the application as it was intended.
- Finally, before making the final version, the diagram should be reanalyzed and reworked as many times as possible to make it correct.
Now, let’s discuss about the relationships which we are using in class diagram.
Relationships and Type of Relationships:
There are 4 types of relationships, which we can set up between classes:
- Associations
- Dependencies
- Aggregations
- Generalizations
Associations:
These are the semantic connections between classes.
It may be both bi-directional and unidirectional.
Bi-directional associations are drawn either with arrowheads on both ends or without arrow heads altogether.
So, between two classes what is a semantic connection you can describe that one using Association. For this Association you may have to create a separate Association class.
In case of bi-directional you can put arrows on the both sides you can have the arrowheads otherwise you may not use any arrow that will also indicate that this line is a bi-directional one.
Example:
The above diagram shows the association relationship between two classes.
In this example, we are having two classes: House and Person. Also, we can see that, there is no arrow on the line joining two classes. That means, it is having the bi-directional relationship.
Dependencies:
These also connect two classes.
Dependences are also unidirectional and show that one class is depending on the definition of the another class and may be depicted by an arrow.
Example:
Aggregations:
Aggregations are the stronger form of association.
An aggregation is a relationship between a whole and parts.
Example:
The above diagram shows aggregation relationship.
Here, we are having the employ list which is consisting of multiple employees. So, we denoted the aggregation with a symbol(a shown in diagram). That means, the employ list is having aggregate of the employee class objects.
Generalizations:
These are used to show an inheritance relationship between two classes.
Example:
The above diagram shows generalization relationship.
In this example, there is a parent class which is having two child classes also known as the subclass or derived class or inherited classes.
So, the child 1 and child 2 are inheriting the properties of parent class. Also, child 1 and child 2 may have some other extra properties.
For frontend projects, check and implements these beginner’s friendly projects :- TOP 7 PROJECTS FOR BEGINNERS TO PRACTICE HTML & CSS SKILLS
Want backlinks to your website? Follow this article and get to know in very easy way. How You Can Create High Quality Backlinks In 2021?
Learn about 404 ERROR page – EVERYTHING YOU NEED TO KNOW ABOUT 404 ERROR PAGE FOR SEO
For competitive and university level exams learning with MCQs visit the below links–
Learn about HTML :- Multiple choice questions on HTML
Do practice of C++ programming :- Multiple choice questions on CPP programming
Do practice of C programming :- Multiple choice questions on C programming
Learn more about Software Engineering: Multiple choice questions on SE
In case, you find any typographical, grammatical or any other error in our site then kindly inform us. Don’t forget to provide the appropriate URL along with error description.
Thanks in advance.
Let me know in comment if you have any doubt.
Remarkable! Its actually amazing piece of writing, I have got
much clear idea concerning from this paragraph.