Design mode slightly talk

zhaozj2021-02-16  77

Design mode slightly talk

Before the design mode, I think we should first understand why you want to learn design mode.

Let's take a look, how to define mode: Each mode describes the problem defined around us and continues to occur, and the core of the problem solution. This way, you can use the scheme again and again without having to repeat labor.

Therefore, we learn design patterns, which is to design accessible, maintainable, scalable systems.

Of course, just briefly describe, why we want to learn and design a little conceptual thing. Below, we have to go deep into the way.

Class mode and object mode.

1. The relationship between class mode processing classes and subclasses, these relationships are built, static, and it is determined at compile time.

2. The relationship between the object mode processing objects, which can be varied at runtime.

From the above, class mode is the relationship between processing classes, and the object mode is the relationship between the objects. The former is static, and then, it is dynamically changed at any time.

But now most of the models belong to the object mode.

Create a model.

The creation mode is abstracted. Solve how to dynamically decide how to create objects, create what object, and how to combine and represent these objects. The creation mode describes how to construct and encapsulate these dynamic decisions.

When the system is now more and more dependent on object synthesis, the creation mode is becoming more and more important. However, some of the topics that are often duplicated in creation models.

1. How did they hide the information of which specific classes are hidden?

2. How do they hide these instances of these classes, how to create and organize information together.

3. They allow you to create, who creates, how to create, how to create, and create these aspects provides great flexibility.

Simple factory

Simple factory model is a class mode.

Which type of product instance is created by a factory class based on incoming parameters.

This mode is designed to factory, abstract products, and three roles of specific products. Among them, the factory is a specific class of the core, including business logic with close-related applications. Customers directly call the factory to create product objects.

For the customer, what it can know about the product's only information comes from abstract parent Product, which can only specify a factory to return a product, and the factory will create one according to your business logic (such as running environment, time setting, etc.). ConcreteProduct, and transform it into Product to return to customers.

Factory Method

Factory method is a class creation mode.

The factory method is to further abstract and promotion of simple factories. In the factory method, the factory class has become an abstract class, and its actual creation will be completed by its specific subclasses.

The intention of the factory method is to define a factory interface that creates a product object, and delays the actual creation work to the subclass.

Abstract factory (Abstract Factory)

Abstract plants are the most abstract and most general forms in all plant modes.

The abstract factory can provide a connection to the customer, allowing customers to create product objects in multiple product families without having to specify the specific type of product.

The above is just a speck of designing the basic concepts of design patterns, as well as interpretation of the concept of more detailed factories. These are all the teachers' explanations and slides in the class. After reading it, it is more understanding, and some may be described unclear. If there is a need, I will put these understandings in the next few days, plus the implementation of the design pattern in Java, and then make up a detailed article.

转载请注明原文地址:https://www.9cbs.com/read-23841.html

New Post(0)