Original Analysis of 9 kinds of Legends of UML
2014-7-23 Read 307 Reviews 0 relationships between classes in UML diagrams: Dependency, generalization, association, aggregation, composition, implementation
class and class Diagram 1) Class (class) encapsulates the data and behavior, is an important part of object-oriented, it is a collection of objects with the same properties, operations, relationships collectively. 2) in the system, each class has a certain responsibility, responsibility refers to the task of the class, that is, the class to complete what kind of function, what kind of obligations to bear. A class can have a variety of responsibilities, well-designed classes generally have only one responsibility, in defining classes, the responsibility of the class is decomposed into the properties and operations of the class (that is, methods). 3) The class's attribute is the data responsibility of the class, the class's operation is the class's behavior responsibility
I. Dependency relationship (dependence)
dependency Relationship (dependence): Assuming that Class A changes cause a change in class B, the name Class B depends on Class A.
• Dependency (Dependency) is a usage relationship in which a change in a particular thing can affect other things that use the thing and use dependencies when it is necessary to indicate that one thing is using another. In most cases, a dependency is embodied in a method of a class that uses an object from another class as a parameter. • In UML, a dependency relationship is indicated by a dashed line with arrows, and the relying party points to the relying party.
public class Driver {public void drive (car car) {car.move (); } ...... } public class Car {public void Move () {...} ...... }
There are three types of dependencies:
1. Class A is a local variable in class B (a method).
2. Class A is a parameter of class B method;
3. Class A sends messages to Class B, which affects the change of Class B;
ii. generalization Relationship (generalization)
generalization Relationship (generalization): A is the parent class of B and C, B,c has a public class (parent class) A, stating that A is a generalization (generalization, also called generalization) of B,c
• Generalization relationships (generalization), also known as "is-a-kind-of" relationships, are used to describe the relationship between a parent class and a subclass, which is also known as a base class or superclass, and a subclass is also known as a derived class. In UML, the generalization relation is represented by a straight line with a hollow triangle. • When code is implemented, use an object-oriented inheritance mechanism to implement generalization relationships, such as using the extends keyword in the Java language, and using the colon ":" in c++/c#.
public class person { protected string name; protected int age; public void move () { ...... } Public void say () { ...... } } public class student extends person { private string studentNo; public void study () { ...... } }
In UML, there are three requirements for generalization relationships:
1, the subclass and the parent class should be exactly the same, the parent class has the properties, operations, subclasses should have;
2. In addition to the information that is consistent with the parent class, the subclass includes additional information;
3. Where instances of the parent class can be used, instances of subclasses can also be used;