Class diagram is a static diagram. It represents the static view of an application. Class diagram is not only used for visualizing, describing, and documenting different aspects of a system but also for constructing executable code of the software application. Show
Class diagram describes the attributes and operations of a class and also the constraints imposed on the system. The class diagrams are widely used in the modeling of objectoriented systems because they are the only UML diagrams, which can be mapped directly with object-oriented languages. Class diagram shows a collection of classes, interfaces, associations, collaborations, and constraints. It is also known as a structural diagram. Purpose of Class DiagramsThe purpose of class diagram is to model the static view of an application. Class diagrams are the only diagrams which can be directly mapped with object-oriented languages and thus widely used at the time of construction. UML diagrams like activity diagram, sequence diagram can only give the sequence flow of the application, however class diagram is a bit different. It is the most popular UML diagram in the coder community. The purpose of the class diagram can be summarized as −
How to Draw a Class Diagram?Class diagrams are the most popular UML diagrams used for construction of software applications. It is very important to learn the drawing procedure of class diagram. Class diagrams have a lot of properties to consider while drawing but here the diagram will be considered from a top level view. 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. The following points should be remembered while drawing a class diagram −
The following diagram is an example of an Order System of an application. It describes a particular aspect of the entire application.
The following class diagram has been drawn considering all the points mentioned above. Where to Use Class Diagrams?Class diagram is a static diagram and it is used to model the static view of a system. The static view describes the vocabulary of the system. Class diagram is also considered as the foundation for component and deployment diagrams. Class diagrams are not only used to visualize the static view of the system but they are also used to construct the executable code for forward and reverse engineering of any system. Generally, UML diagrams are not directly mapped with any object-oriented programming languages but the class diagram is an exception. Class diagram clearly shows the mapping with object-oriented languages such as Java, C++, etc. From practical experience, class diagram is generally used for construction purpose. In a nutshell it can be said, class diagrams are used for −
A Class in UML diagram is a blueprint used to create an object or set of objects. The Class defines what an object can do. It is a template to create various objects and implement their behavior in the system. A Class in UML is represented by a rectangle that includes rows with class names, attributes, and operations.
A Class Diagram in Software engineering is a static structure that gives an overview of a software system by displaying classes, attributes, operations, and their relationships between each other. This Diagram includes the class name, attributes, and operation in separate designated compartments. Class Diagram helps construct the code for the software application development. Class Diagram defines the types of objects in the system and the different types of relationships that exist among them. It gives a high-level view of an application. This modeling method can run with almost all Object-Oriented Methods. A class can refer to another class. A class can have its objects or may inherit from other classes. In this UML Class Diagram tutorial, you will learn: Benefits of Class Diagram
Essential elements of A UML class diagramEssential elements of UML class diagram are:
Class NameThe name of the class is only needed in the graphical representation of the class. It appears in the topmost compartment. A class is the blueprint of an object which can share the same relationships, attributes, operations, & semantics. The class is rendered as a rectangle, including its name, attributes, and operations in sperate compartments. Following rules must be taken care of while representing a class:
Attributes:An attribute is named property of a class which describes the object being modeled. In the class diagram, this component is placed just below the name-compartment. A derived attribute is computed from other attributes. For example, an age of the student can be easily computed from his/her birth date. Attributes characteristics
RelationshipsThere are mainly three kinds of relationships in UML:
Dependency A dependency means the relation between two or more classes in which a change in one may force changes in the other. However, it will always create a weaker relationship. Dependency indicates that one class depends on another. In the following UML class diagram examples, Student has a dependency on College Generalization: A generalization helps to connect a subclass to its superclass. A sub-class is inherited from its superclass. Generalization relationship can’t be used to model interface implementation. Class diagram allows inheriting from multiple superclasses. In this example, the class Student is generalized from Person Class. Association: This kind of relationship represents static relationships between classes A and B. For example; an employee works for an organization. Here are some rules for Association:
In this example, the relationship between student and college is shown which is studies. Multiplicity A multiplicity is a factor associated with an attribute. It specifies how many instances of attributes are created when a class is initialized. If a multiplicity is not specified, by default one is considered as a default multiplicity. Let’s say that that there are 100 students in one college. The college can have multiple students. Aggregation Aggregation is a special type of association that models a whole- part relationship between aggregate and its parts. For example, the class college is made up of one or more student. In aggregation, the contained classes are never totally dependent on the lifecycle of the container. Here, the college class will remain even if the student is not available. Composition: The composition is a special type of aggregation which denotes strong ownership between two classes when one class is a part of another class. For example, if college is composed of classes student. The college could contain many students, while each student belongs to only one college. So, if college is not functioning all the students also removed. Aggregation vs. Composition
Abstract ClassesIt is a class with an operation prototype, but not the implementation. It is also possible to have an abstract class with no operations declared inside of it. An abstract is useful for identifying the functionalities across the classes. Let us consider an example of an abstract class. Suppose we have an abstract class called as a motion with a method or an operation declared inside of it. The method declared inside the abstract class is called a move (). This abstract class method can be used by any object such as a car, an animal, robot, etc. for changing the current position. It is efficient to use this abstract class method with an object because no implementation is provided for the given function. We can use it in any way for multiple objects. In UML, the abstract class has the same notation as that of the class. The only difference between a class and an abstract class is that the class name is strictly written in an italic font. An abstract class cannot be initialized or instantiated. Abstract Class NotationIn the above abstract class notation, there is the only a single abstract method which can be used by multiple objects of classes. Example of UML Class DiagramCreating a class diagram is a straightforward process. It does not involve many technicalities. Here, is an example: ATMs system is very simple as customers need to press some buttons to receive cash. However, there are multiple security layers that any ATM system needs to pass. This helps to prevent fraud and provide cash or need details to banking customers. Below given is a UML Class Diagram example: Also Check:- UML Diagrams: History, Types, Characteristics, Versions, Tools Class Diagram in Software Development LifecycleClass diagrams can be used in various software development phases. It helps in modeling class diagrams in three different perspectives. 1. Conceptual perspective: Conceptual diagrams are describing things in the real world. You should draw a diagram that represents the concepts in the domain under study. These concepts related to class and it is always language-independent. 2. Specification perspective: Specification perspective describes software abstractions or components with specifications and interfaces. However, it does not give any commitment to specific implementation. 3. Implementation perspective: This type of class diagrams is used for implementations in a specific language or application. Implementation perspective, use for software implementation. Best practices of Designing of the Class DiagramClass diagrams are the most important UML diagrams used for software application development. There are many properties which should be considered while drawing a Class Diagram. They represent various aspects of a software application. Here, are some points which should be kept in mind while drawing a class diagram:
Conclusion
Also Check:- UML Diagram Tutorial for Beginners: Learn UML Online for FREE |