Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Design pattern-structural type

2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/03 Report--

I. adapter mode

The Adapter Pattern mode acts as a bridge between two incompatible interfaces. This type of design pattern is a structural pattern, which combines the functions of two separate interfaces. This pattern converts the interface of one class into another interface that the customer wants. The adapter pattern allows classes that cannot work together because the interfaces are not compatible.

The way to do this is that the adapter inherits or relies on existing objects to implement the desired target interface.

It is important to note that the adapter is not added at the time of detailed design, but rather solves the problem of the project in service.

II. Bridging mode

Bridge is used to decouple abstraction from implementation so that the two can change independently. This type of design pattern belongs to structural pattern, which decouples the two by providing a bridge structure between abstraction and implementation.

The bridging pattern converts inheritance relationships into association relationships, which are based on the abstract layer, thus reducing the coupling between classes and reducing the amount of code writing.

Example: drawing, here is a paintbrush, you can draw squares, rectangles, circles (we all know how to do this, I won't explain it). But now we need to color these shapes. There are three colors: White, gray and black. Here we can draw the figure in 3 "3" 9: White square, white rectangle, white circle. At this point, we almost know that there are two solutions: solution one: provide a variety of color versions for each shape. Scheme 2: combine colors and shapes according to actual needs.

Usage scenario: 1. If a system needs to increase more flexibility between the abstract role and the concrete role of the component, and avoid establishing a static inheritance relationship between the two levels, they can establish an association at the abstract layer through the bridging pattern. 2. Bridging mode is especially suitable for systems that do not want to use inheritance or that the number of system classes increases sharply because of multi-level inheritance. 3. There are two independent changing dimensions in a class, and both dimensions need to be extended.

III. Filter mode

Filter pattern (Filter Pattern) or standard pattern (Criteria Pattern) is a design pattern that allows developers to filter a set of objects using different standards and connect them in a decoupled manner through logical operations. This type of design pattern belongs to structural pattern, which combines multiple standards to obtain a single standard.

But this is also a pattern?

Four. combination mode

The most critical aspect of the implementation of the composition pattern is that simple objects and composite objects must implement the same interface. This is why the composition pattern can handle composite objects and simple objects consistently. Objects are combined into a tree structure to represent a "part-whole" hierarchy. The combination mode enables users to use individual objects and composite objects consistently.

Example: the components in the mobile game engine can be combined with each other to form a tree structure.

Five. decorator mode

This pattern creates a decoration class that wraps the original class and provides additional functionality while maintaining the integrity of the class method signature.

In this pattern, the decorator and the decorated inherit the same base class and implement the same interface. The decorator will depend on the decorated, and then the decorator will depend on each other. In the decoration, the decorator will first call the previous decorator's decoration method, and then begin to add their own decoration function.

In my last mobile game project, I used this pattern to achieve the function of a prompt box. By dividing the prompt box into several parts, each part is a decorator, and when I implemented each part with code, then establish a mapping of numbers to each class name, and the planner can configure the parts he needs according to his own needs.

VI. Appearance mode

Facade Pattern hides the complexity of the system and provides the client with an interface through which the client can access the system. This type of design pattern belongs to structural pattern, which adds an interface to the existing system to hide the complexity of the system.

There is nothing to say about this, but the facade in puremvc is to provide some external interfaces for a system or several systems. The outside world only interacts with facade.

Seven. Enjoy the meta-model

The shared meta-mode (Flyweight Pattern) is mainly used to reduce the number of objects created to reduce memory footprint and improve performance. This type of design pattern is a structural pattern, which provides a way to reduce the number of objects and improve the object structure required by the application.

Is the technology of the object pool.

Eight. agent mode

The proxy mode mainly solves the problems caused by accessing the object directly, for example, the object to be accessed is on the remote machine. In object-oriented systems, direct access to some objects will bring a lot of trouble to consumers or system structures for some reasons (such as high overhead in object creation, or some operations require security control, or out-of-process access). We can add an access layer to this object when we access this object.

The difference from other patterns: 1. The difference from the adapter pattern: the adapter pattern mainly changes the interface of the object being considered, while the proxy pattern cannot change the interface of the proxy class. 2. The difference between the decorator mode and the decorator mode: the decorator mode is to enhance the function, while the proxy mode is to control it.

End.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report