Design principles and Design patterns

Source: Internet
Author: User

The original * * * * may need to change the application, separate them (encapsulated), and do not mix with the code that does not need to change.

The original * * * for interface programming, rather than for implementation programming, here for interface programming really mean "for super type Supertype programming", the key is polymorphism.

The original * * * Multiple use combination, less with inheritance.

Mode * * * * Strategy mode (Strategy pattern): Defines the algorithm family (a group of classes or methods), packaged separately, so that they can replace each other, this pattern allows the algorithm to change the independent client using the algorithm.

——————————————————————
The original * * * for the interaction between the loose coupling design efforts.

MODEL * * * Observer mode: Defines a one-to-many dependency between objects (the observer relies on the observable or the subject), so that when an object changes state, all its dependents are notified and automatically updated.

The JAVA.UTIL package has built-in observer patterns that make it easier to implement the pattern, but the observer pattern is flawed.

———————————————————————

Inheritance is statically determined at compile time, all subclasses inherit the same behavior, and the combination extends object behavior and relies on delegates, which can be extended dynamically at run time.

The original * * Open and Close principle: class should be extended development, to modify the closure.

It is impossible to make every part of the design follow the open and closed principle, focus on the most likely change in the design, and then use the open and closed principle.

The decorator can be seen as a wrapper.

Both the adorner and the decorated person have the same super type.

Because the decorator and the decorated person have the same super type, so in any need to be decorated in the occasion, can be decorated with the replacement.

The decorator can add his or her own behavior before/after the act of entrusting the decorated person, and even remove the decorated person's behavior for a specific purpose.

Mould * * Decorator Mode: Dynamically attaching responsibilities to objects, and to extend functionality, adorners provide more flexible alternatives than inheritance.

Adorners are often created in a pattern similar to a factory (factory) or builder (builder) to prevent decorative coding errors.

————————————————————————
A static factory method gets an object that does not need to create an object to instantiate the object, but its disadvantage is that the behavior of creating an object method cannot be changed by inheritance.

Modular * * * Factory Method Mode: Defines an interface for creating objects, but subclasses decide which class is instantiated. The factory method lets classes defer instantiation to subclasses.

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.