This is the fifth day of my participation in the August Wen Challenge.More challenges in August

preface

This article will take a look at the representation of the relationship between classes and classes. We often read some design pattern articles, books or some big projects will involve the representation of the relationship between classes, usually using the class UML class diagram to do the illustration. This article we will do a basic literacy, to avoid the next time to see when directly skip, the last did not understand the embarrassment 😅.

Represents a class

Format description:

  1. Line 1: Class name
  2. Line 2: Class attributes (fields)
  3. Line 3: Class methods (functions)

Symbol Description:

  1. + : public
  2. – : private
  3. # : protected

Other notes:

  1. The italics of the class name indicate an abstract class

Represents an interface

Format description:

  1. Use the first line of the interface name<<interface>>tag
  2. Line 1: Interface name
  3. Line 2: interface methods

Represents the inheritance relationship of a class

Use hollow triangle + solid line to indicate class A1 inherited from class A.

Example: in the object-oriented development process, will have the same attributes of the class to encapsulate, the actual use of the class through inheritance of these attributes. For example, Student and Worker can have a common parent class Person.

Represents the interface implementation relationship

Hollow triangle + dotted line indicates that class A needs to implement interface 1.

Example class description: in the object-oriented development project, will have the same method of class encapsulation, the actual use of the class through the implementation of the interface to get these standard methods. For example, Student and Worker can have public interface Sports and implement running, Rope skipping, etc.

Represents the association of a class

Use the implementation + arrow to indicate that class A contains class B.

For example, the behavior of one class can vary depending on the influence of another. For example, the Person class will watch the weather change to decide whether to add clothes.

Represents an aggregation (weak ownership) relationship for a class

Use hollow diamonds and solid line arrows to indicate that class A can have class B, but that class B is not part of class A.

For example, a class can have a representation of another class, as School can have a representation of student and it can have no representation of student.

Represents a composite (strongly owned) relationship of classes

Use solid diamond + solid line arrow to indicate that class B is part of class A.

For example, the presentation of a class is accomplished through a combination of classes. For example, the Person class is composed of eye, nose, mouth, Ear, and so on.

Represents the dependencies of a class

Use dotted arrows to indicate that class A depends on class C and class D.

For example, the performance of a class may include an external dependency condition in addition to the combined part, for example, the Person class needs to depend on water, money, etc.

conclusion

“Big Talk design pattern” said that programming is a technology, but also an art, UML class diagram is also a need to slowly skilled, you HXD can be collected for query 🙏.