1. Association
When a class object is a member of another class object, the two classes are associated.
C #CodeAs follows:
///
/// Correlation
///
Public class husband
{
Private wife and wife;
}
Wife of public class
{
}
UML diagramAs follows:
2. Multiple links
Refers to the number of instances of Class B corresponding to an instance of Class.
C #The Code is as follows:
///
/// Multiple links
///
Public class dog
{
Private leg [] LEG = new leg [4];// It is debatable here that the relationship between the dog and the leg should be a combination, because the dog is gone and the leg is gone, you can replace it with a dog and a bag of dog food added by zhangjun
}
Public class leg
{
}
UML diagramAs follows:
3. directionality In Association
In a large company, the company's president only knows the core staff, not all ordinary staff, and all the staff know the president.
C #The Code is as follows:
///
/// Directionality In Association
///
President of public class corporation
{
Private core staff;
}
Public class core staff
{
President of a private company, president of a large company;
}
Public class common employee
{
President of a private company, president of a large company;
}
UML diagramAs follows:
4. Aggregation relationship
Is a special case of the association relationship. It indicates that the two classes have a relationship between the whole and the part. The Hollow End is the whole, and the other end is the part. the aggregation relationship does not implicitly disappear as a whole, resulting in partial disappearance.
If the company goes bankrupt, but the employee is still there, it will not perish.
C #The Code is as follows:
///
/// Aggregation relationship
///
Public class company
{
Private employee;
}
Public class staff
{
}
UML diagramAs follows:
5. Composite relationship
It is a special case of an aggregation relationship. Based on the meaning of the aggregation relationship, the semantics of "hidden, hidden" is added between the whole and the part. The solid diamond represents the whole, and the other end represents the part.
C #The Code is as follows:
///
/// Composite relationship
///
Public class tree
{
Private leaf and leaf;
}
Public class leaf
{
}
UML diagramAs follows:
6. Dependency
The dependency is weak compared with the association relationship. Changes in the "dependent" may affect the "dependent ".
C #The Code is as follows:
///
/// Dependency
///
Public class human
{
Private food;
}
Public class grain
{
}
UML diagramAs follows:
7. inheritance relationship
Class A is a type of class B. For example, if the following code is used for students or college students, the keyword abstract statement is used in C.
C #The Code is as follows:
///
/// Inheritance relationship
///
Public abstract class student
{
Public abstract void Learning ();
}
Public class pupils: Students
{
Public override void Learning ()
{
}
}
Public class students: Students
{
Public override void Learning ()
{
}
}
UML diagramAs follows:
8. Implementation relationship
One party puts forward this requirement as a requirement, and the other party fulfills this requirement. Use the keyword interface statement in C #. If the following code shows how to walk to the park, I can walk or take a bus.
C #The Code is as follows:
///
/// Implementation relationship
///
Public interface to park
{
Void walk ();
}
Public class walking: Go to the park
{
Public void walking ()
{
}
}
Public class: Go to the park
{
Public void walking ()
{
}
}
UML diagramAs follows: