The relationship in the class diagram is roughly as follows
lGeneralization _
l Association
l Dependency
l Combination
l Aggregation
generalization
Generalization is the relationship between subsets and supersets, often expressed by inheritance and implementation;
Inheritance: solid line and hollow triangle arrow representation from subclass to superclass
Implementation: dashed line and hollow triangular arrow representation from subclass to superclass
rely
Dependency often means that one party (customer) knows about another party (provider) and when the other party (provider) changes, it affects one party (customer). This is often referred to as coupling.
There are many types of dependencies, the more common ones ;
Has a parameter of provider type
Receive a parameter of provider type
Provider is a superclass or interface
Send a message to the provider. Visibility to providers may be properties, parameter variables, local variables, global variables or class methods.
public class Client { /// <summary> /// 1. The UpdatePrintMsg method receives the Supplier object as a parameter, and then sends a GetPrintMsg message to it. /// It can be seen that the client object has parameter visibility to the supplier, and has the coupling of sending messages, so the supplier have dependencies. /// If the latter changes, the client class will be affected. /// </summary> /// <param name="supplier"></param> public void UpdatePrintMsg(Supplier supplier) { var msg = supplier.GetPrintMsg(); Console.WriteLine( " Client: call-" " + msg); } } public class Supplier { public string Msg => " Provider Information " ; public string GetPrintMsg() { return Msg; } }
The client calls and outputs: client: call-" provider information
Client client = new Client(); client.UpdatePrintMsg(new Supplier());
looking at another example
public class Client { /// <summary> /// The PrintCartNum method calls the static method of supplier. Therefore the client object has a static method dependency on the supplier class /// . /// </summary> public void PrintCartNum() { long cartNum = Supplier.GetCartId(); Console.WriteLine(cartNum); } } public class Supplier { public static long GetCartId() => 1000_2000_3000_4000; }
The client calls and outputs: 1000200030004000
Client client = new Client(); client.PrintCartNum();
association
An association is a has a relationship, with a navigation arrow (ie, solid line + arrow) pointing from the source object ( order ) to the target object ( OrderItem ), indicating that an attribute of the Order is the orderItem object. In the concrete implementation, it is often expressed as a property of the class
Associations can also be used without arrows to indicate bidirectional associations
polymerization
Aggregation is a vague association in uml that imprecisely implies a whole - part relationship (like many ordinary associations)
Why even define this term? To quote one of the founders of uml : "Although it doesn't give too much semantics to the aggregation, everyone thinks it is necessary. Think of it as a placebo for modeling." So follow the advice of the uml founders , don't bother to use aggregates. Instead, use combinations when appropriate.
combination
Composition, also known as composition aggregation, is a strong whole - part aggregation relationship and has utility in some models. Always imply some variant of "own - part". Combinations are indicated using solid diamond arrows.
The composition relationship has the following meanings: 1 ) At a certain moment, some instances can only belong to one composition instance.
2 ) A part must always belong to a composition; 3 ) A composition is responsible for creating and deleting its parts, either by itself or in collaboration with other objects to create / delete parts. In short, the sword is in people, and the sword destroys people.