When developing embedded software, for more complex projects, before writing code, we usually conduct requirements analysis and software function design first. The more common way to achieve this is to use UML modeling.
This article will introduce some commonly used UML diagram knowledge points and drawing examples in embedded development.
This article first introduces the class diagram in UML.
1 Introduction to UML
1.1 What is UML
UML, the full name of Unified Model Language, is a standard language composed of a set of diagrams for describing, visualizing and documenting products of object-oriented systems. UML represents a set of best engineering practices that have proven to be successful in modeling large and complex systems. UML is a very important part of developing object-oriented software and the software development process. In embedded system design, using UML for modeling and documenting can usually achieve twice the result with half the effort.
1.2 Origin and Development of UML
The emergence of UML originated from the combination and unification of the methods of three object-oriented masters:
-
Booch Method by Booch
-
OOSE, Martin/Odell method created by Jacobson
-
OMT, Shlaer/Mellor method created by Rumbaugh
Although these methods are different, their common concepts are very similar. The three were combined and the first version called "Unified Method" was launched in October 1995: Unified Method 0.8.
Later, the UML 1.0 version named "Unified Modeling Language" was submitted to the OMG (Object Management Group). By the end of 1997, the OMG
UML1.1 was officially adopted as the standard modeling language based on object-oriented technology. UML1.1 and UML 2.0 (released in 2005) are two milestone versions in the history of UML.
1.3 Various diagrams in UML
UML has many different types of diagrams, including:
-
Static diagrams: use case diagrams, class diagrams, package diagrams
-
Dynamic diagrams: activity diagrams, state diagrams, sequence diagrams, collaboration diagrams
These different diagrams can provide a description of the system from different perspectives. In addition to programmers, large-scale software development processes also include product, design, and testing personnel. These people have different concerns about different aspects of the system, so different levels of detail need to be considered during modeling.
In this article, let's first introduce the basic knowledge of UML class diagram.
2 UML class diagram example
2.1 Visio design UML class diagram
Create a new Visio file. When you open it, you will be prompted to create a certain type of diagram. Here, select "Software and Database -> UML Class Diagram"
After clicking OK, you will enter the UML class diagram editing interface. On the left, you can see the basic elements for UML class diagram editing:
Drag these elements to the editing and decoding panel on the right, and you can see the basic structure of these elements:
2.2 A UML class diagram example
Below is an example of a UML class diagram:
-
Animal is an abstract class. One of its subclasses is Bird. Bird can be divided into geese, ducks, penguins, and a subclass of Duck is Donald Duck. These are inheritance relationships.
-
Animals rely on oxygen and water, which is a dependent relationship.
-
Wings are part of a bird, and wings cannot exist independently. They belong to a synthetic (or combined) relationship.
-
Many geese gather together to form a flock, which is an aggregation relationship.
-
Geese can fly, which belongs to the interface (or implementation) relationship
-
Penguins 'understand' climate patterns, a correlation
3 Introduction to UML class diagram elements
The following is a detailed introduction to the various elements in the UML class diagram.
3.1 Graph
The diagrams in the UML class diagram mainly include class diagrams and interface diagrams .
3.1.1 Class Diagram
The class diagram is the main element in the UML class diagram. The structure of the class diagram consists of 3 lines:
-
Line 1: is the name of the class
-
Line 1: It is the attribute of the class, that is, the various member variables of the class
-
Line 1: is the class method, that is, various member functions of the class
Main: If the class name is italic, it means it is an abstract class, such as the animal here
For symbols before properties and methods:
3.1.2 Interface Diagram
The interface diagram is similar to the class diagram. The biggest difference from the class diagram is that the top is marked with "<<interface>>" to indicate that this is an interface diagram. The interface diagram has only two lines:
-
Line 1: is the name of the interface
-
Line 1: is the method of the interface, that is, the function implementation
Note: There is another "lollipop" representation of the interface diagram. The interface name is next to the circle, and the implementation of the interface method is implemented in the class.
3.2 Relationship
The connections between graphs are connected through various relationship lines, including: interface relationships, dependency relationships, inheritance relationships, composition relationships, aggregation relationships, and association relationships .
3.2.1 Interface relationship (implementation relationship)
Interface relationship, also known as implementation relationship, is represented by a triangle arrow + dotted line , with the arrow pointing to the interface , indicating that the class is the implementation of all features and behaviors of the interface
3.2.2 Dependencies
Dependency describes a usage relationship, that is, the implementation of one class requires the assistance of another class. It is represented by a normal arrow + a dotted line , with the normal arrow pointing to the user.
3.2.3 Inheritance relationship (generalization relationship)
Inheritance relationship, also known as generalization relationship, is represented by a triangle arrow + solid line , with the arrow pointing to the parent class , indicating that the child class inherits all the characteristics and behaviors of the parent class.
3.2.4 Synthesis relationship (combination relationship)
A composite relationship, also called a combination relationship, describes a relationship between a whole and a part, where the part cannot exist independently of the whole. It is represented by a solid diamond + a solid line , with the solid diamond pointing to the whole.
3.2.5 Aggregation
Aggregation describes the relationship between the whole and the parts, and is represented by a hollow diamond + solid line , with the hollow diamond pointing to the whole.
3.2.6 Relationship
An association relationship describes the structural relationship between objects of different types and is represented by a normal arrow + a solid line , with the arrow pointing to the associated object .
A bidirectional association can have two arrows or no arrows. A unidirectional association has one arrow.
4 Conclusion
This article introduces the basics of UML class diagrams, including 2 and 6 relationships, and demonstrates how to draw a UML class diagram using Visio software.