Before learning UML class diagrams, recommend a good website with lots of open source projects: Http://www.oschina.net/project.
Also recommend an open source project: STARTUML, all of the following class diagram and the diagram between the classes are drawn with STARTUML.
Let's take a sample before learning UML:
Comments:
Class First line: Class name Second line: Attribute (field or property) Third line: Action (method or behavior) Note: If the class name is italic, this class is an abstract class |
Interface Lollipop notation Interface name next to circle Interface methods appear in the class implementation |
Interface Rectangular notation with "interface" at the top First line: Interface name Second line: interface method |
Note the methods of each class and the symbols in front of the fields The + sign indicates that the public,-number is private, #表示protected |
UML Class diagram detailed:
When drawing a class diagram, it is important to clarify the relationship between classes and classes. The relationships of a class are generalized (generalization), implemented (realization), dependent (Dependency), and associative (association). The association is divided into general relationship and aggregation relation (Aggregation), synthesis relation (composition). Here we understand these relationships in conjunction with examples.
Note: You can actually remember this. Class relationships are: generalization (generalization), Association (association). Generalization: inheritance and implementation. Associations: Dependencies, general associations, aggregation associations, composition associations. |
Basic concepts:
Class Diagram: Class diagrams are the most commonly used and most important diagrams in object-oriented system modeling and are the basis for defining other diagrams. Class diagrams are primarily used to display a static model of classes, interfaces, and static structures and relationships between them in a system.
3 Basic components of a class diagram: Class Name, property, method.
Note: Whether the field or method of a class has a + or--such as an access modifier followed by a type, the type of the field is the type of the variable, and the type of the method is the return value type of the function.
Generalization (generalization): Represents the relationship of Is-a, which is the most coupling between objects, and the subclass inherits all the details of the parent class. Direct use of inheritance expressions in languages. In a class diagram, a solid line with a triangular arrow is used, and the arrow points from the subclass to the parent class.
Implementation (Realization): In the class diagram is the relationship between the interface and the implementation. This is nothing to say. In a class diagram, a dashed line with a triangular arrow indicates that the arrow points from the implementation class to the interface.
Dependency (Dependency): One of the weakest associations between objects, is a temporary association. the code generally refers to the call relationships that are established by local variables, function parameters, and return values for other objects. A class calls some of the methods in a dependent class to accomplish some of the duties of this class. In a class diagram, a dashed line with arrows indicates that the arrow is pointing from the class to which it is dependent.
Scene: Originally people and Computers have no relationship, but because of accidental opportunities, people need to use a computer to write programs, when people rely on the computer.
A dependency diagram of a class and a class is generally a using reference in a program.
Association (Association): a reference relationship between objects, such as the relationship between a commodity class and an order class. This relationship is typically expressed using the properties of the class. Association is divided into General Association, Aggregation Association and Combinatorial Association. The latter two are analyzed later. In a class diagram, a solid line with an arrowhead is used, and the arrow points from the class that is associated with it. Can be one-way (commodity and order classes) and bidirectional (Order class and Customer Class).
A1->A2: A1 know that A2,A1 knows the existence of A2, A1 can invoke methods and properties in A2
Scenarios: Orders and commodities, orders include goods, but the goods do not understand the existence of the order.
A one-way correlation diagram between classes and classes:
Public class Order { public list<product> order; Public void Addproducttoorder (product product) { order. ADD (product); } } Public class Product { }
Aggregation (Aggregation): Represents the relationship of Has-a, which is an unstable containment relationship. Stronger than the general association, there is the relationship between the whole and the local, and there is no whole, local can also exist alone. If the company and the employee relationship, the company contains employees, but if the firm closed, employees can still change the company. In a class diagram using a hollow diamond representation, the diamond is directed from the part to the whole.
Combination (composition): Represents the relationship of Contains-a, which is a strong containment relationship. The combined class is responsible for the life cycle of the grouped classes. is a stronger aggregation relationship. Part can not be separated from the whole existence. If the relationship between the company and the department, without the company, the department can not exist; the relationship between the questions and options in the questionnaire, and the relationship between order and order options. In a class diagram using a solid diamond representation, the diamond is directed from the part to the whole.
Multiplicity (multiplicity): Typically used in association, aggregation, and composition. Is the representation of how many associated objects exist. Use numbers: An asterisk (number) indicates. For example, a cut-off notification can be associated with 0 to n trouble sheets.
UML Class Diagram