Synthetic/aggregation reuse principle, use composition/aggregation as much as possible, and do not use class inheritance as much as possible.
Aggregation (Aggregation) represents a weak ' owning ' relationship, which shows that a object can contain a B object but a B object is not part of a object.
Synthesis (composition) is a strong ' own ' relationship that embodies a strict part-and-whole relationship, as well as part and whole life cycle.
Prioritizing the composition/aggregation of objects will help you keep each class encapsulated and focused on a single task so that class and class inheritance levels remain small and unlikely to grow into uncontrollable behemoths.
Inheritance is a strongly-coupled structure. Subclasses change as the parent class changes, so be sure to consider using a relationship that is ' is-a '.
Bridging mode (bridge), separating the abstract part from its implementation, so that they can vary independently.
Package Bridge; Public Abstract class IMP { publicabstractvoid operation ();}
Package Bridge; Public class extends Imp { @Override publicvoid operation () { System.out.println (" Concreteimpa operation ");} }
Package Bridge; Public class extends Imp { @Override publicvoid operation () { System.out.println (" CONCRETEIMPB operation ");} }
Package Bridge; Public Abstract class IMP { publicabstractvoid operation ();}
Package Bridge; Public class extends Abstraction { publicstaticvoid main (string[] args) { abstraction Abstraction=new refinedabstraction (); Abstraction.setimp (new Concreteimpa ()); Abstraction.operation (); Abstraction.setimp (new CONCRETEIMPB ()); Abstraction.operation (); }}
To realize that the system may have multiple angles of classification, each of which is likely to change, then the multi-angle is separated to allow them to change independently, reducing the coupling between them.
Big talk Design pattern note synthesis/aggregation multiplexing principle