Big talk design pattern - the classic UML diagram

UML graphics

 

a ) Class (class): The class name shown in italics is abstract class, " + " is public , " - " is private , and " # " is protected . The first behavior is the class name; the second behavior is the characteristic (field or property); the third behavior is the operation (method or behavior). For abstract classes, class names are in italics.

b ) Interface (interface): There is an " interface " at the top of the interface to distinguish it from a class, or a label in the form of a lollipop.

c ) Inheritance: The hollow triangle + solid line is the inheritance relationship. Birds inherit the characteristics of animals.

d ) Implement the interface: hollow triangle + dashed line. Such as the realization of the flying interface.

e ) Association can be used when one class needs to know about another class . Use solid arrows. For example, penguins are associated with climate, because penguins need to know the climate.

f ) Aggregation vs Composition : _ _

   - Aggregation is a weak "owning" relationship, ie: A object can contain B object, but B object is not part of A object. Each individual contained in the A object can exist independently from the A object . Indicated using open diamonds + solid arrows. Like a flock of geese assembled by geese.

   - Composition is a strong "owning" relationship, ie: B object is part of A object. have the same life cycle. Indicated using solid diamonds + solid arrows. Such as wings are part of a bird.

  - Aggregation and Composition can have cardinality.

 

g ) Dependency ( Dependency ): represented by a dotted arrow , pointing to the dependent object. Such as animals depend on oxygen, water.

 

Summarize:

It can be seen from the above that no matter what the relationship is, such as association, composition, aggregation, etc., it is also realized through polymorphism, abstraction, and inheritance in object-oriented languages.

The association, composition, aggregation, etc., although the meanings are different, are mostly implemented in the code by defining another object (or its reference, pointer) in one object.

 

refer to:

wps_clip_image-23508

 



 

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326677205&siteId=291194637