Priority: composit | aggregate. Do not use special types of extends and association.
Aggregation: it indicates the 'havn' relationship or the relationship between the whole and the part.
Composition can be understood as a strongly correlated relationship, with a much stronger 'havn' relationship. A new merged object has full control over its components, including their creation/destruction,
Component Objects in a compositing relationship cannot be shared with another compositing relationship.
A component object belongs to only one compositing relationship at a time.
Synthesis is the aggregation by value, and aggregation is the reference aggregation by reference)
· Composite/aggregation Reuse
The only way to store/retrieve component objects for new objects is through interfaces.
The internal details of the component object. The new object is invisible.
This reuse mechanism supports packaging/requires less Dependencies
Each new object can focus on a task.
New objects can dynamically reference instances of the same type as component objects. For example, setuserlist (User userobj) can be seen as an interface in some users.
This merging/aggregation multiplexing mechanism has multiple instances to be managed
· Use extends
Extends is a unique reuse mechanism of OO and can be abused easily.
Inheritance is the reuse of types. It extends or adds new functions to existing functions by extending the implementation of an existing object. The basic class must capture common attributes/form, the subclass must extend/override some attributes/form.
Inheritance destroys the encapsulation of the superclass because it exposes the processing details to the subclass.
Water Wave effect. If the superclass processing mechanism is changed, the corresponding changes to the subclass are very large.
Is a difference from has
Is a represents a class.
Has a indicates that a class is a role of a class.
· The composite/aggregation reuse mechanism can be applied to almost any environment, but inheritance can only be applied to a limited environment.