C # object-oriented model design 25th (last): Design Model Summary

Source: Internet
Author: User
Tags in domain

1. Creation Mode:

Singleton: Solves the number of instantiated objects, such as factories and object pools in the abstract factory. In addition to Singleton, other creation modes solve the coupling relationship brought by new.

Abstract Factory: creates a series of interdependent objects and can change the series at runtime.

Factory method: create a single object, which is used in abstract factory.

Prototype: Creates a new object by copying the prototype.

Factory method, abstract factory, and builder all require an additional factory class to instantiate "one-side object", while prototype is a prototype (a special factory class) to clone the "variable object ".

If you encounter a "variable type", the initial design usually starts with the factory method. When there are more complex changes, consider refactoring to the other three factory modes (Factory method, abstract factory, builder ).

2. Structural Model

Adapter: Focus on the conversion interface, adapt the inconsistent interface to the object, used for the oldCodeReuse, class library migration, etc.

Bridge: focuses on the separation of abstraction and implementation, and supports multi-dimensional changes of objects.

Composite: focuses on unified interfaces, converts "one-to-many" relationships to "one-to-one" relationships, shields the internal implementation structure of object containers, and achieves consistency between objects and object containers.

Decorator: Pay attention to stable interfaces. Under this premise, the object function is extended to avoid subclass expansion.

Facade: it focuses on simplified interfaces, shields the complexity of subsystems, and provides higher-level interfaces for customers to access.

Flyweight: focuses on retaining interfaces and uses sharing technology internally to optimize Object Storage (by sharing a large number of fine-grained objects to provide system performance ).

Proxy: Pay attention to the fake lending interface. By adding indirect proxy, more control is implemented to shield complexity.

3. behavior mode

Template Method: EncapsulationAlgorithmStructure, defines the algorithm skeleton, and supports algorithm substep changes.

Strategy: focuses on encapsulating algorithms and supports algorithm changes. By encapsulating a series of algorithms, the algorithm can be replaced independently of the customer at any time.

State: it focuses on encapsulation of State-related behaviors, and supports state changes. By encapsulating the object state, it changes its behavior when its internal state changes.

Memento: stores and restores the status of encapsulated objects.

Mediator: focuses on encapsulating interaction between objects. By encapsulating complex interaction between a series of objects, they do not need to explicitly reference each other to achieve decoupling.

Chain of responsibility: focuses on encapsulating Object Responsibility, supports responsibility changes, and implements transaction processing by dynamically building a responsibility chain.

Command: encapsulates requests as objects and supports request changes. by abstracting a group of behaviors as objects, the decoupling between the behavior requestor and the behavior implementer is realized.

Iterator: focuses on encapsulating changes in specific fields, supports changes in collections, and shields complex structures inside collection objects to provide customersProgramTransparent traversal of it.

Interpreter: focuses on encapsulating changes in specific fields, supports frequent changes in domain issues, expresses problems in specific fields as sentences under certain syntax rules, and then constructs an interpreter to explain such sentences, to solve the problem.

Observer: focuses on encapsulating object notifications, supports communication object changes, changes object status, and notifies and updates objects dependent on it.

Visitor: focuses on encapsulating object operation changes, and supports adding new operations to the class structure at runtime. In the class hierarchy, you can define new operations acting on these class instances without changing the categories.

Correct treatment mode:

The design mode is built on the basis of the system changes, where there are changes, where the design mode is applied.

The design pattern should be obtained in an evolutionary manner, and the changes of the system can be accurately located only after constant evolution.

The design model cannot be a pattern. It is a soft force of software design, rather than a standard, and should not be exaggerated.

Conclusion

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.