Describe the design pattern in one sentence

Describe the design pattern in one sentence

[[143440]]

As the title says, actually, I think this is very difficult.

Unless - just to give yourself a reminder, so that you can quickly recall the memories of this design pattern at a glance.

The following is a summary of my notes when I was studying "Design Patterns in Big Words", some of which are from its author Cheng Jie. (Thank you very much for building such a smooth learning channel for the mysterious design pattern)

1. Creation type:

(1) Singleton: Consider when only one instance is required.

(2) Factory method: The factory method is generally used first to solve the object creation problem.

(3) Abstract Factory: When the factory method cannot meet multiple series of problems, it is refactored into an abstract factory.

(4) Builder: The construction implementation of multiple components is the same, but the required components and construction order are different.

(5) Prototype: considered when the initialization information does not change.

2. Structural type:

(1) Adapter: Allow classes with incompatible interfaces to work together. (Fixing the barn door after the sheep have been bolted)

(2) Decoration: Dynamically add additional responsibilities to a single object, which is more flexible than generating subclasses.

(3) Bridging: Change the inheritance relationship to a combination relationship so that the two can change independently. (Prepare for a rainy day)

(4) Combination: Use a tree structure to represent the hierarchical relationship of "whole-part" so that the use of single objects (leaf nodes) and combined objects (branch nodes) is consistent.

(5) Flyweight: It uses sharing technology to support a large number of fine-grained objects and save costs.

(6) Proxy: Controls access to a single object.

(7) Appearance: The high-level interface of the subsystem, avoiding third parties in the direct relationship between two classes.

3. Behavioral:

(1) Observer: One-to-many dependency relationship. If one end changes, multiple ends are notified and automatically updated. (The target and observer can achieve weak coupling)

(2) Template method: inheritance + rewriting solves the problem of code duplication.

(3) Command: Decouple the request sender from the specific implementer, and can queue, cancel, and redo requests to support transactions. (Multiple requests, single processing)

(4) Chain of responsibility: Arrange the handlers into a chain and pass the request along the chain. (Single request, multiple handlers)

(5) State: When the state within an object changes and different operations are performed, the state transfer logic is not in the if/switch, but between subclasses. It is easier to add/modify states and state transitions.

(6) Interpreter: If a particular problem occurs frequently enough, it is necessary to define the grammar representation and the interpreter itself.

(7) Mediator: The mediator encapsulates a series of object interactions, reduces coupling between objects, and facilitates reuse. (Many friends)

(8) Visitors: Consider when the Elements are relatively stable and Visitors are easy to increase. (Friends are more about quality than quantity)

(9) Strategy: Encapsulate a series of algorithms one by one and make them interchangeable, making them easy to switch, understand, and expand.

(10) Memo: It does not destroy encapsulation, but takes the state of the object into account and requires that the state be restored. (Maintain encapsulation boundaries)

(11) Iterator: Separate the access and traversal of a collection from the collection object into the iterator.

<<:  After he sold the company, he paid his employees 150 months’ salary!

>>:  Why do we need motion design?

Recommend

Why did eBay return to China together with JD.com?

[[132426]] After a year of preparation, JD.com...

Chun Ge, the painter, "Introduction to Human Body Painting"

Introduction to human figure drawing - character c...

5-picture mind map teaches you 7 major community operation methods!

WeChat group marketing has been very popular in r...

A must-read for flu season! The latest flu vaccination guide for 2022 is here

Recently, the Chinese Center for Disease Control ...

Jia Zhen, "Little Red Book Merchant Camp No. 6"

Jia Zhen's "Little Red Book Merchant Cam...

Do you think you can operate well just by reading the dry goods? Stop dreaming!

Just like I have heard a lot of truths, but I sti...

iOS 15 turns off personalized ads, no impact on App Store search ads

According to MacRumors, starting with iOS 15 and ...

The fourth session of the Aiti Tribe Technical Clinic

【51CTO.com original article】 [51CTO original arti...

Big iPhone screen: Accelerating the demise of one-handed gaming

The new generation of iPhone will have two screen...

Half sober and half drunk! Can you drive after drinking "Jiangxiang Latte"?

“Wine and coffee, I love this one” Source: Weibo ...

How does Zhihu continue to accurately direct traffic to private domains?

More and more people in the market are beginning ...

Every time a bunch of bananas is picked, a banana tree dies?

gossip "For every bunch of bananas picked, a...