Big talk Design pattern note synthesis/aggregation multiplexing principle

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.