Understand design patterns by comparing implementations in JavaScript and Java [Updated from time to time]

Introduction

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.

What is a design pattern?

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 pattern category

Design patterns can be categorized from different perspectives

Creational patterns

** 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

Structural pattern

** 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

Behavioral patterns

** 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

reference

[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

Understand design patterns by comparing implementations in JavaScript and Java [Updated from time to time]
[Updated from time to time] Summary of design patterns in Java
Understand the Strategy pattern by comparing JavaScript and Java code
Understand the Decorator pattern by comparing JavaScript and Java code
Understand the State pattern by comparing JavaScript and Java code
Understand the Composite pattern by comparing JavaScript and Java code
[Updated from time to time] LetCode algorithm and library
Summary from the beginning to Chapter 1 of the introduction to design patterns learned in the Java language
vtkXMLUnstructuredGridReader Summary (updated from time to time)
Summary of Chapter 2 of Introduction to Design Patterns Learned in Java Language
vtkOpenFOAMReader Summary (Updated from time to time)
[Notes / Updated from time to time] This and that of Azure Functions
Engineer vocabulary (updated from time to time)
Chapter 4 Summary of Introduction to Design Patterns Learned in Java Language
Summary of Chapter 3 of Introduction to Design Patterns Learned in Java Language
Tensorflow memo [updated from time to time]
Private Python handbook (updated from time to time)
vtkClipPolyData / DataSet Summary (Updated from time to time)
[Updated from time to time] PostmarketOS related notes
Summary of vtkThreshold (updated from time to time)
Summary of gcc options (updated from time to time)
Notes on machine learning (updated from time to time)
OpenFOAM post-processing cheat sheet (updated from time to time)
progate Python learning memo (updated from time to time)
To represent date, time, time, and seconds in Python
Useful help sites, etc. (updated from time to time)
A memorandum of commands, packages, terms, etc. used in linux (updated from time to time)
Convert timezoned date and time to Unixtime in Python2.7
How to measure processing time in Python or Java
Machine learning python code summary (updated from time to time)
Apache settings, log confirmation, etc. (* Updated from time to time)
[Updated from time to time] Review of Let Code NumPy
I read the Chainer reference (updated from time to time)
List of my articles that may be useful in competition pros (updated from time to time)