Vernacular design patterns-Summary of creation Design Patterns

Source: Internet
Author: User

So far, I have finished learning several design patterns of the created model. Let's take a look at them.

It takes a short time. It is better to create a model that is relatively simple and will not be so smooth in the future. since there is no real practice in the project, so far, I think I have not mastered it, just a little understanding of the design model.

People speak English, so I also summarize the knowledge I know about the creation-type design patterns for your reference and discussion, hope to make progress together with colleagues.

 

The creation mode is mainly used to solve the coupling relationship between new objects. Besides singleton and prototype, factory is used to instantiate objects, prototype is used to clone objects through prototype (that is, abstraction.

 

To put it bluntly, the creation mode is to separate the objects that may change frequently, so that the changes do not affect the entire system.

 

There are five gof design modes: Creation Mode.

The Singleton mode is used to control the number of objects created. Generally, a specified number of objects can be created by changing the number of objects.

 

The factory method mode is the most basic creation mode and one of the most basic design modes. Since it is object-oriented programming, of course we need to create objects. The factory method mode solves the basic object creation problem. The object creates an instance through its own factory.Creation pointIt depends on the object's own abstraction instead of specific implementation. During compilation, you only need to know which object to create (abstraction). during runtime, you need to know which object will be created. The behavior of an object is similar, so the abstraction is the same. But the specific implementation is different. For example, a car can turn, but the specific implementation of a motorcycle and a car turns is different, but the abstraction is the same. Here, we only say that the car is about to turn during compilation, and we will tell you more at runtime.ProgramWhich car is turning.

 

Abstract Factory mode is developed based on the factory method mode. Factory method only solves the problem of which object to create, while Abstract Factory solves the problem of which series of objects to create. There may be many associations and interactions between these objects. In other words, for example, we must use bedding, including bed sheets, beddings, And Sofa towels. We will not use one set for the rest of our lives. We will definitely need to replace it with others. If there are any bad ones, we need to replace them with new ones (Here we assume the whole set of bad ones/replications ). Abstract Factory is used. Create a set of bedding at a time, without modifying anything, just add new beddings, beddings, and pillowcases, and then tell the system that I want to use this new one when calling. It is okay, in line with the object-oriented principle of closing the modification and opening the extension.

 

Like the factory method, the builder mode creates an object. However, it creates a super complex object. It allows us to create different representations through the same creation process. Here,AlgorithmIt is stable, but each part of the object is unstable and often changes. For example, the process of building a house, building a house, such as laying the foundation, building a shelf, and laying bricks remains the same. This is a stable algorithm. However, it may change frequently when creating doors and windows. It is possible that the House will use the door of Factory A, but that house will use the door of factory B. This requires the builder mode. No matter who you use, you must build a house.

 

The prototype mode interprets the object-oriented Dependency inversion principle. When a manager object depends on a specific implementation, we can abstract this implementation (provided that this object is changeable) so that the manager object depends on this abstraction. In this way, in the future, it will be easy to expand new abstract-based implementations. In the managerAbstractionTo create a required number of objects. In this way, the manager only depends on abstraction. I think this is why we advocate interface-oriented programming.

 

In short, the Creation Mode solves the problem of object creation in software design. Generally, it is only when we encounter a variable class that we can use the creation mode, it depends on the ease of change and system features.

 

You are welcome to make a brick. I know thisArticleSimple and simple, just hope that the coainiao fly over to reap the harvest.

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.