[1] Preliminary Exploration of the design model

Source: Internet
Author: User

Mode, as its name implies, is to sum up the methods of doing things. In terms of experience, there is a good way to deal with things that can get twice the result with half the effort. What is a good mode in software development?

In my opinion, a good mode is simply to ensure that you do not need to make more code modifications when dealing with changes in requirements, but simply expand on the original basis, that is, close the changes, open extension. "

To achieve this, the relationship between system modules must not be too close. The result is that when one module needs to be modified, another module also needs to be modified accordingly, the cost of software development has increased, and we cannot even meet new requirements. This is very bad. Therefore, we must achieve low coupling in the design of the system architecture (considering possible demand changes, any complicated design is costly, the system may be very inefficient when there is no need for special processing. NET will be familiar with calling virtual functions and other mechanisms ). If you meet the low coupling conditions, the general situation also shows that your system has a high cohesion (class responsibility is clear ). The classic design model allows us to build a system architecture with this feature.

Today, I will summarize the functions of several design patterns:

1. Policy mode: defines the algorithm family and encapsulates them separately so that they can replace each other. This mode allows algorithm changes to be independent of customers who use algorithms.

2. Observer mode: defines one-to-many dependencies between objects. In this way, when an object changes its status, all objects dependent on it will receive notifications and update automatically.

3. dynamically attach the responsibility to the object. If you want to extend the function, the modifier provides another option that is different from inheritance.

4. Abstract Factory mode: provides an interface for creating families of related or dependent objects without specifying specific classes.

5. Factory method mode: defines an interface for creating objects, but the subclass determines which class is to be instantiated. The factory method delays the class Instantiation to the subclass.

6. Single-piece mode: ensure that a class has only one instance, but provides global access points.

7. Command mode: encapsulate requests into objects, which allows you to parameterize other objects using different requests, queues, or log requests. The command mode also supports undo operations.

8. Adapter mode: converts an interface of a class to another interface that the client expects.

9. Appearance mode: provides another unified interface to access a group of interfaces in the subsystem. The appearance defines a high-level interface to make the subsystem easier to use.

10. template method: Define the skeleton of an algorithm in a method, and delay some steps to the subclass. The template method allows subclass to redefine some steps in the algorithm without changing the algorithm structure.

11. iterator mode: provides a method to access each element of an aggregate object sequentially without exposing its internal representation.

12. Combination Mode: allows you to make objects into a tree structure to represent the "whole/part" hierarchy. Combination allows the customer to process individual objects and object combinations in a persistent manner.

13. State mode: allows an object to change its behavior when its internal state changes. The object seems to have modified its class.

14. Proxy mode: provides a replacement or a placeholder for another object to access this object.

15. compound mode: The compound mode combines two or more modes to form a solution to solve repeated general problems.

 

It takes not long to learn the design pattern. I feel that this knowledge is very important in software development. As a beginner developer, I think it is necessary to learn it, especially when looking at other people's code, we can know it, but even more, it is very helpful for programmers to improve.

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.