I decided to write a design pattern in Python in a university laboratory. However, even though I didn't understand the design pattern properly, I felt that I couldn't write it in Python. So, let's compare and understand the design patterns in Java and your favorite JavaScript. If you write all the patterns in this article, it will be long, so I will create an article for each pattern and fill in the table below.
Customs to solve common problems in software design and make them reusable 23 kinds of GoF (Gang of Four) design patterns are famous GoF is "Erich Gamma" "Richard Helm" "Ralph Johnson" "John Vlissides" Introduced the term design pattern into software development for the first time in "Design Patterns for Reuse in Object-Oriented Programming"
Design patterns can be categorized from different perspectives
** Solve the problem by focusing on the mechanism for creating objects and controlling the process of object creation **
Pattern name | Overview |
---|---|
Factory Method | Create an instance of the derived class based on the passed data and events |
Abstract Factory | Create an instance of a class without revealing the details of the concrete class |
Builder | Separate the object creation process from the representation form. Always create objects of the same type |
Prototype | Use a fully initialized instance when copying |
Singleton | A class with only one instance that can be accessed globally |
** It's about synthesizing objects and is used to help you understand the relationships between different objects **
Pattern name | Overview |
---|---|
Adapter | Make interfaces of different classes correspond so that even classes that do not support the interface can be used in combination. |
Bridge | Detach the object's interface from the implementation, allowing the interface and implementation to be modified independently |
Composite | By treating the structure of individual objects and composites of objects uniformly, you can do more than treat them separately. |
Decorator | Dynamically add processing to an object |
Facade | One class hides the complexity of the entire subsystem |
Flyweight | Use small-sized instances to efficiently share information that is used everywhere |
Proxy | Surrogate object to replace the real object |
** Focused on improving and simplifying communication between different objects in the system **
Pattern name | Overview |
---|---|
Interpreter | Add linguistic elements to your application to accommodate the grammar of the target language |
Template Method | Create a chunk of the algorithm in the method and delay the step to the subclass |
Chain of Responsibility | How to pass requests in sequence in a series of objects and find an object that can handle that element |
Command | Separate the command execution operation from the position of issuing the command |
Iterator | Access the elements of a collection in sequence without knowing the internal behavior of the collection |
Mediator | Simplify interactions between classes and prevent classes from directly referencing each other |
Memento | Record the internal state of an object so that you can restore it later |
Observer | How to notify many classes of changes and ensure consistency between classes |
State | Change the behavior of an object when its state changes~ |
Strategy | Encapsulates the algorithm inside the class and makes the algorithm selection independent of the class implementation |
Visitor | Add a new operation to a class without changing it |
[Introduction to Design Patterns Learned in the Enhanced and Revised Java Language](https://www.amazon.co.jp/%E5%A2%97%E8%A3%9C%E6%94%B9%E8%A8%82% E7% 89% 88Java% E8% A8% 80% E8% AA% 9E% E3% 81% A7% E5% AD% A6% E3% 81% B6% E3% 83% 87% E3% 82% B6% E3% 82% A4% E3% 83% B3% E3% 83% 91% E3% 82% BF% E3% 83% BC% E3% 83% B3% E5% 85% A5% E9% 96% 80-% E7% B5 % 90% E5% 9F% 8E-% E6% B5% A9 / dp / 4797327030) JavaScript design pattern
Recommended Posts