Design pattern reading note (-)

xiaoxiao2021-03-06  67

Design pattern reading note (-)

2004-11-21

1, what is design mode?

Object-oriented software design experience summary.

The goal is to make people more simple, easy to reuse successful design and architectural structure. Mainly to complete the system design.

Master Christopher Alexander proposed: "Every pattern describes a problem that has been repeated around us, as well as the core of the solution. This way, you can use the scheme again and again without having to repeat labor."

The definition of the above is a generalized definition of the design mode.

We apply it to the domain-oriented software, which forms a narrow definition of design patterns: design mode is to solve a particular method for a particular object-oriented software problem.

2, design mode classification

Design mode itself, 4 elements:

Pattern name takes a name

Problem Description When used mode

Solution describes the composition, interrelationships, and how to coordinate the pattern.

Problems with the effect of effect model application and use mode should be weighed

Depending on the purpose of the usage mode, the pattern is divided into 3 classes:

● Creating: Solve how to create an object.

Abstract factory abstract factory model

Builder generator mode

Factory Method Factory Mode Mode

Prototype prototype mode

Singleton single case model

● Structural: Solve the problem of how to make a correct combination or object.

Adapter adapter mode

Bridge bridge mode

Compsite combination object mode

Decorator decoration mode

Facede appearance mode

Flyweight Enjoyment Yuan Mode

Proxy proxy mode

● Behavioral: Solve how to interact between class or objects and how to assign responsibilities.

Chain of Responsibility duties

Command command mode

Iterator iterator mode

Mediator intermediard mode

Mementor memo mode

Observer observer mode

State status mode

Strategy Policy Mode

Template Method Template Method Mode

Visitor visitor mode

3, abstract factory model

Name: Abstract Factory Abstract Factory Model, also known as Kit Problem:

The house is made up of walls, doors, windows, floors, ceilings, pillars. If we write a software built a house for our customers, we will see the walls, doors, windows, floors, ceilings, pillars as different classes: Wallclass, Doorclass, Windowclass, CEILINGCLASS, PILLARCLASS.

Now we create a new class HouseFactory. There is CreateWall (), createFloor (), createFloor (), create, createfloor (), create, createFloor (), createPillar (), creation and returns the corresponding object. If WallClass, Doorclass, Windowclass, CEILINGCLASS, FLOORCLASS, PILLARCLASS, as a product, then class A is like a factory that produces these products. This is why use the word used in the factory.

Our software is complete, and customers are very satisfied. However, our customers want to export this software, he found a problem, this software is too local, and it is a Chinese-style house. So he wants our software to build a different regional house.

solution:

1. We build an abstract HouseFactory, declare in the class:

Createwall ();

CREATEDOOR ();

Createfloor ();

Createceiling ();

Createpillar ();

2, at the same time, establish an abstract product ABSTRACT Product Product product class:

Wall, Door, Floor, Ceiling, Pillar

3. Establish different houses to create specific factories for different styles: CONCRETE FACTORY Class:

ChinaHouseFactory: HouseFactory

GreecehouseFactory: HouseFactory

. . . . . .

4. Different products, concrete products for different styles: Conomer PRODUCT:

ChinaWall: Wall

Chinadoor: door

GreeceWall: Wall

Greecedoor: Door

. . . . . .

effect:

● Repeat the last two steps, you can add new styles.

● Use the abstraction class declared in the previous two steps to implement the operation.

Abstract factory mode is not the abstract factory class that is declared, but it is declared a series of abstract product classes, we can operate the specific product classes we have implemented or not implemented by using these abstract product classes, and guaranteed them consistency. The specific class is separated.

You may have discovered that this software can't build your two-story villa because it doesn't have stairs. To do this, we have to define the Stair abstraction, but also increase the CreateStair abstraction method; the most important thing is that we have to increase the corresponding Stair class in the 76 style has been completed, which is a big trouble.

Abstract factory model is relatively weak in adapting to new products. This is a shortcoming it. In other words, once the factory is established, the factory's products have been limited (you should not expect a food factory to produce electrical appliances)

Photo:

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

New Post(0)