Horizontal comparison of 7 structural design modes

Horizontal comparison of 7 structural design modes


The main function of the structural design pattern is to combine multiple classes or objects to make their functions more abundant.

        Serial number                                        Pattern name                                Constituent elements effect
1 Agency model 1. Real theme class
(provide business methods)
2. Agent class
(call real theme business methods, expand other methods)
For some reason, the visitor object cannot directly reference or access the target object, so add a proxy object as an intermediary.
2 Adapter mode 1. Target interface
(the business interface expected by the system)
2. Adaptor
(target component or interface that needs to be adapted)
3. Adapter
(reference the target adaptor in the constructor, define the business interface method, and call the adaptor internally (Method of fitter)
Classes or objects that cannot work together due to incompatible interfaces can work together through adapter conversion.
3 Bridge mode 1. Abstract roles
(including references to realized objects, calling methods of realized roles)
2. Realized roles
(business methods for realizing realizing roles)
When a class has multiple independent changing dimensions, and each dimension needs to be expanded
4 Decorative pattern 1. Component role
(implement business interface)
2. Decoration role
(reference construction role in the constructor, define business interface, call business interface of construction role, and call additional functions at the same time)
Need to dynamically add additional functions to the object without changing the structure of the object
5 Appearance mode 1. Appearance role
(referring to the subsystem in the constructor, providing the method that the customer calls, and calling the subsystem method within it)
2. Subsystem role
(realizing the business function of the subsystem)
3. Customer role
(creating an instance of the appearance role, Call its method)
Provide unified access to multiple subsystems
6 Flyweight model 1. Flyweight role
(providing business methods and obtaining external state through parameters)
2. Non-sharedweight role
(receiving external state in the constructor, and you can set and obtain external state)
3. Flyweight factory role
(managing shareware roles, When a client requests a shareware object, first check whether it exists in the system, return directly if it exists, and create a new shareware object if it does not exist)
Applied to scenes where there are a large number of identical or similar objects in the system that need to be created
7 Combination mode 1. Leaf component
(leaf node object, no child nodes)
2. Branch component
(branch node object, with child nodes. Storage and management of child components, usually including add\remove\getChild and other methods)
Used to express the "part-whole" relationship, so that users have consistent access to single objects and combined objects.

Guess you like

Origin blog.csdn.net/weixin_44135121/article/details/108212748