UML class diagram is a graphical representation of object-oriented system for construction and visualization. Class diagram in Unified Modeling Language (UML) is a static structure diagram, which describes the system structure by displaying the system structure:
- Their attributes
- Operation (or method),
- And the relationship between objects.
What is a class?
Classes are blueprints for objects. Objects and classes go hand in hand. We can’t talk about one without talking about the other. The focus of object-oriented design is not objects, but classes, because we use classes to create objects. Therefore, a class describes what an object will be, but it is not the object itself.
In fact, a class describes the type of an object, and an object is an available instance of a class. Each object is built from the same blueprint and therefore contains the same components (properties and methods). The standard meaning is that objects are classes and instances of objects – objects have state and behavior.
Dogs have state – color, name, breed and behavior – swing, bark, eat. An object is an instance of a class.
UML class symbols
A class represents a concept that encapsulates the state（attribute）And behavior（operation）。 Each property has a type. eachoperationThere is oneautograph。_ The class name isUnique required information_。
- The name of the class appears in the first partition.
- Properties are displayed in the second partition.
- The property type is displayed after the colon.
- Attributes map to member variables (data members) in code.
Class operation (method):
- The actions are displayed in the third partition. They are the services provided by the class.
- The return type of the method is displayed after the colon at the end of the method signature.
- The return type of the method parameter is displayed after the colon after the parameter name. Operations are mapped to class methods in code
The +, – and symbols in front of the property and operation names in the class represent the visibility of the property and operation.
- +Represents a public property or action
- -Represents a private property or action
- Represents a protected property or operation
Each parameter in an operation (method) can be expressed as in,outorinout, they specify the direction relative to the caller. The directivity is displayed before the parameter name.
Perspectives of class diagram
The choice of perspective depends on how far you go in the development process. For example, in developingIn the process of domain model, you rarely surpassConceptual view。analysis model UsuallyConceptual and normative perspectivesMixed together.Design modelDevelopment usually focuses onStart from normal angleAnd then evolved intoRealization angle。
The diagram can be interpreted from a variety of perspectives:
- Conceptual: represents concepts in the domain
- Specification: focus on the interface of abstract data type (ADT) in software
- Implementation: describes how a class will implement its interface
Perspective affects the amount of detail to provide and the kind of relationship worth presenting. As mentioned above, the class name is the only required information.
Relationships between classes
UML is more than just beautiful pictures. If used correctly, UML can accurately convey how to implement code from diagrams. If interpreted accurately, the implemented code will correctly reflect the designer’s intention. Can you describe the meaning of each relationship relative to your target programming language, as shown in the figure below?
If you don’t recognize them yet, this section won’t help you understand UML class relationships. One class may involve one or more relationships with other classes. Relationships can be one of the following types:
Inheritance (or generalization):
Generalization is the taxonomic relationship between more general classifiers and more specific classifiers. Each instance of a particular classifier is also an indirect instance of a general classifier. Therefore, specific classifiers inherit the characteristics of more general classifiers.
- Indicates a “yes” relationship.
- Abstract class names are shown in italics.
- Subclass1 and subclass2 are the specialties of superclasses.
The following figure shows an example of an inheritance hierarchy. Subclass1 and subclass2 are derived from superclass. The relationship is displayed as a solid line with a hollow arrow pointing from the child element to the parent element.
Inheritance example – shape
The following illustration shows an example of inheritance with two styles. Although connectors are drawn differently, they are semantically equivalent.
Association is the relationship between classes in UML class diagram. They are represented by solid lines between classes. Associations are usually named with verbs or verb phrases that reflect the real-world problem domain.
- A structural link between two peer classes.
- There is an association between Class1 and class2
The following figure shows an example of a simple association. There is an association connecting < < control > > class Class1 and < < boundary > > class class2. The relationship is displayed as a solid line connecting the two classes.
The cardinality is expressed as:
- One to many
- Many to many
A special type of association.
- It represents a “part” of the relationship.
- Class2 is part of Class1.
- Many instances of class2 (represented by *) can be associated with Class1.
- Objects of Class1 and class2 have separate lifetimes.
The following figure shows an example of aggregation. The relationship is shown as a solid line with an unfilled diamond at the end of the association, which is connected to the class representing aggregation.
- A special aggregation in which a part is destroyed when the whole is destroyed.
- The objects of class2 live and die together with Class1.
- Class2 cannot stand on its own.
The following figure shows an example of the composition. The relationship is shown as a solid line with a solid diamond at the association end, which is connected to the class representing the whole or composition.
An object of one class may use an object of another class in the code of a method. If the object is not stored in any fields, it is modeled as a dependency.
- A special type of association.
- If a change to the definition of one class may result in a change to another class, the class exists between two classes (and vice versa).
- Class1 depends on class2
The following figure shows an example of a dependency. The relationship is displayed as a dashed line with an open arrow.
The following figure shows another example of a dependency. The person class may have a hasread method with a Book parameter, which returns true if the person has read the book (possibly by checking some databases).
An implementation is the relationship between a blueprint class and an object that contains the details of its respective implementation level. It is said that this object implements the blueprint class. In other words, you can understand it as the relationship between the interface and the implementation class.
For example, the owner interface can specify methods to get and dispose of properties. The person and Corporation classes need to implement these methods in potentially completely different ways.
Class diagram example: order system
Class diagram example: Gui
Class diagrams may also have annotations attached to classes or relationships.
Find free class diagram tools?
Visual paradise online freeIs a free online drawing software, supporting class diagrams, other UML diagrams, ERD tools and organization chart tools. It has a simple but powerful editor that allows you to create class diagrams quickly and easily. The free UML editor has no advertising, no access deadline, and no restrictions, such as the number of charts, shapes, etc. You have charts created for personal and non-commercial purposes.
Quickly draw class diagram
Free UML software
Free class diagram for personal use:
- Unlimited charts and shapes
- Unlimited access time
- No advertising
Draw any number of charts. Export graphics to PNG / JPG / GIF / SVG / PDF.
Simple and powerful
UML diagrams can be simple and interesting. Here are some features of our class diagram editor:
- Drag to create a shape
- Well connected connector (no separation)
- Inline editing class properties and operations
- Draw your own picture with your own shape
- Hundreds of chart examples and templates
An impressive picture
Use the alignment wizard to precisely position the shape. Use a series of formatting tools to format class diagrams: shape and line format, font style, rotatable shape, shape alignment and distribution, embedded image and URL, shadow effect, etc
Class diagram (37 templates)
Token ring based LAN
File output (inductive use)
Telephone (for association use)
GOF design pattern – agent
GOF design pattern Flyweight
GOF design pattern – facade
GOF design pattern – decorator
GOF design pattern – Composite
GOF design pattern – bridge
GOF design pattern – adapter
GOF design pattern – singleton
GOF design pattern – Prototype
GOF design pattern – plant approach
GOF design pattern – generator
GOF design pattern – Abstract Factory
GOF design pattern – visitors
GOF design pattern template method
GOF design pattern – Strategy
GOF design mode – Status
GOF design pattern – observer
GOF design pattern memento
GOF design pattern – mediator
GOF design pattern – iterator
GOF design pattern – interpreter
GOF design mode – commands
GOF design pattern – responsibility chain
Class diagram – ordering process
Class diagram – constraints on classes and packages
Class diagram – class in package (airline)
Association level and self association
Sales order system