“Van Gogh with the Left Ear” 11 original
The first words
Disclaimer: This article is partly excerpted from Wikipedia, as well as a summary of my years of work. This article is a great tool to use as a UML manual. Please bookmark it and refer to it when you need it.
What is the UML
Wikipedia definition of UML:
UML (Unified Modeling Language) is an open method for illustrating, visualizing, building, and writing artifacts of an under development, object-oriented, software-intensive system. UML represents a set of best engineering practices that have been proven for modeling large-scale, complex systems, especially at the software architecture level.
The language was developed by Grady Buch, Ivar Jacobson, and James Lamb at Rational Software in 1994 and 1995, and further developed in 1996. UML integrates the concepts of Booch, OMT, and object-oriented programming, fusing these approaches into a single, generic, and widely available modeling language. UML is intended to be the standard modeling language for concurrent and distributed systems.
UML is not an industry standard, but it is becoming one under the auspices and sponsorship of the Object Management Group. OMG has previously called on the industry to provide object-oriented theory and implementation methods to produce a rigorous Software Modeling Language. A number of industry leaders have responded in good faith to OMG and helped it create an industry standard.
A few key points can be drawn from wikipedia’s definition:
-
UML is a software modeling language. It’s a de facto industry standard;
-
UML is used to provide object-oriented design theory and implementation methods;
-
UML provides a set of best engineering practices that are useful at the system modeling and software architecture design levels.
Further, we can summarize several keywords: software modeling Language, industry standards, object-oriented, system modeling, architectural design, optimal time.
There are three main models in UML system development:
-
Function model: Shows the functionality of the system from the user’s point of view, including use case diagrams.
-
“Object model” : using concepts such as object, attribute, operation and association to show the structure and foundation of the system, including class diagram and object diagram.
-
Dynamic model: Shows the internal behavior of the system. Including sequence diagram, activity diagram, state diagram.
UML contains a series of diagrams, the most commonly used case diagrams, class diagrams, sequence diagrams, etc. “Only class diagrams will be covered in this article.” The other diagrams will be covered in a future article.
UML class diagram in detail
1. The class description
“Classes” are usually represented in UML as solid rectangle boxes. There are several dividing lines in the rectangular box. Represents the class name, attribute, and method, respectively. As shown below:
-
Class name: The name of the class is in the uppermost rectangle. If the font is italic, it represents an abstract class. (Top part of the picture)
-
Property: The area below the class name. (The middle part of the picture)
-
Method :(the bottom part of the figure)
Note: The “+”, “-“, and “#” before properties and methods indicate access levels:
-
+ : public
-
– : private
-
# : protected
2. Interface description
The class diagram representation of “Interface” is roughly the same as that of a class, except that Interface is added to the Interface name and the visibility of the behavior must be indicated by “+”. The diagram below:
Classes and relationships between classes
There are six relationships between classes:
-
inheritance
-
implementation
-
associated
-
Rely on
-
combination
-
The aggregation
1. Inherit
Inheritance is one of the three main features of object-oriented languages (encapsulation, inheritance, polymorphism). Subclasses inherit from their parent class.
Inheritance relationships in UML class diagrams are represented by hollow triangles + solid lines.
2. Implement
Implementation is similar to inheritance in that the implementation class inherits methods from the interface.
The implementation relationships in UML class diagrams are represented by hollow triangles + dashed lines.
3. The associated
Dependencies are typically represented as private properties of a class.
/ / penguin
public class Penguin {
/ / the weather
private Climate climate;
}
Copy the code
The UML class diagram is shown as follows:
Associations in UML class diagrams are represented by solid arrows.
4. Rely on
Dependencies are embodied in local variables, method parameters, or calls to static methods.
public class Programmer {
public void work(Computer computer){
}
}
Copy the code
The dependencies in UML class diagrams are represented by dotted arrows.
The following code shows three concrete code implementations of dependencies: local variables, method parameters, and calls to static methods.
public class Person{
public void doSomething1(a){
Car car = new Car();// Local variables
.
}
public void doSomething2(Car car){// Method parameters
.
}
public void doSomething3(a){
int price = Car.do(a);// Static method calls
}
}
Copy the code
Combination of 5.
“Combination” is a kind of association relation, indicating a strong “ownership” relation. It reflects the strict relationship between the parts and the whole. Part and whole have the same life cycle.
public class Bird {
private Wing wing;
public Bird(a) {
this.wing = new Wing();
}
}
Copy the code
Composition relationships in UML class diagrams are represented by solid diamonds + solid lines.
6. The aggregation
Aggregation is a kind of association relation, indicating a weak “ownership” relation.
In Java code, geese are social animals, each goose belongs to a group, and a group can have more than one goose.
The weather is cold and the leaves are yellow. . A flock of wild geese flew south, forming an “S” and a “B”. “Autumn” is from the text of first grade Chinese in Human Education Edition
public class WildGooseAggregate {
private List<WildGoose> wideGooses;
}
Copy the code
The aggregation relationships in UML class diagrams are represented by hollow diamond solid lines.
The All in One example
Six relationships between classes were introduced earlier. To better understand these six relationships. Here is a complete example (car). These six relationships are included in this example.
Description:
-
The structure of car class diagram is, indicating that car is an abstract class;
-
It has two inheritance classes: cars and bicycles; The relationship between them is an “implementation” relationship, represented by a dashed line with a hollow arrow;
-
The relationship between car and SUV is also “inheritance”, and the relationship between them is a generalization relationship, represented by a solid line with a hollow arrow.
-
The relationship between car and engine is “combination”, represented by solid line with solid arrow;
-
The relationship between students and classes is “aggregation”, represented by solid lines with hollow arrows;
-
The relationship between the student and the ID card is “association”, represented by a solid line;
-
Students need to use bicycles to go to school. They are “dependent” on bicycles, represented by dotted lines with arrows.
I am Van Gogh left Ear. I graduated from Beijing Institute of Technology and am now the chief architect of a financial consulting company. I once worked in the Middleware team of Alibaba. Immersed in the software industry for more than ten years, I believe that technology can change the world. Can you really write code?
Adhere to the output of technical dry goods, workplace experience and reading comprehension. Welcome to follow the public account “Left Ear Van Gogh”, and continue to learn with me, lifelong growth.
Recommended reading
-
Share a personal project that got me into Ali middleware
-
Do I need to test English for technical interviews?
-
Design mode in Warcraft – Factory Mode
-
I am the Interviewer Design Pattern – singleton pattern
-
Is log.isDebugEnabled needed in the logging framework?