[Java] Summary of design patterns

Purpose I learned all 23 Java design patterns, so I will write them as a memorandum. This article gives an overview of all design patterns.

What is a design pattern? A collection of typical class design patterns designed for more efficient and general-purpose design. Not only is it highly reusable and gives a better view of the entire code, but it also minimizes the extent of the impact during maintenance.

Types of design patterns The design pattern is ・ Object generation ・ Program structure -Object behavior It is roughly classified into three patterns.

Object creation A list and overview of patterns for object creation. All 5 types.
Pattern name Overview
Factory Method Generate multiple subclasses as a pair.
Abstract Factory A class that specializes in Factory Method.
Builder Divide the constructor into a builder class and a director class, and create a complex initial value object.
Prototype Pooling clones makes it easier to create objects.
Singleton Ensure that only one object of that class is created between system startup and shutdown.

Program structure A list and overview of patterns related to the structure of the program. All 7 types.
Pattern name Overview
Adapter You can add appropriate methods without modifying existing classes.
Bridge For two strongly related classes, extend them by inheriting each class so that there is no effect.
Composite By giving a common interface to all objects that form a hierarchical structure, a series of operations can be easily executed.
Decoraror By implementing a common interface, you can add more functionality than class inheritance.
Facade By grouping objects of highly versatile classes, it is easy to share among developers.
Flyweight By pooling the created objects, the load required to create and hold the objects is reduced.
Proxy By having a common interface, hook it when a method is called and add processing. Similar to Decorator.

Object behavior A list and overview of patterns related to object behavior. All 11 types.
Pattern name Overview
Chain of Responsibility Depending on the request type (argument value), select an appropriate object from multiple objects and process it.
Command The processing of the request itself is made into an object, and a request with complicated contents is sent.
Interpreter Since the interpreter can be executed using the object structure obtained as a result of parsing as it is, it is easy to extend the syntax. The
Iterator Iterator interface makes it easily accessible regardless of the structure of the objects.
Mediator You can easily change the content of the interaction and add the part object.
Memento You can take a snapshot of an object's state at a given moment, save it, and use it to restore its original state.
Observer You can easily switch or increase the class to be checked and the class to be checked.
State Even if the state changes complicatedly, the processing contents can be switched simply, and the visibility of the state transition in the code is improved.
Strategy You can easily switch the algorithms used in the program while it is running.
Template Method One big process is decomposed into multiple steps, and the process contents are changed for each step while observing the execution order of the steps.
Visitor Even if there are several types of classes in a set of objects, you can add processing without modifying those classes.

Finally Design patterns are very good in terms of reusability and maintainability, but be aware that if you try to forcefully apply them to a design pattern, you may end up with complicated code.

Recommended Posts

[Java] Summary of design patterns
Java Design Patterns
Summary of Java support 2018
Java design pattern summary
Summary of "Design Patterns Learned in Java Language (Multithread Edition)" (Part 10)
Summary of "Design Patterns Learned in Java Language (Multithread Edition)" (Part 7)
Summary of "Design Patterns Learned in Java Language (Multithread Edition)" (Part 3)
Summary of "Design Patterns Learned in Java Language (Multithread Edition)" (Part 6)
Summary of "Design Patterns Learned in Java Language (Multithread Edition)" (Part 5)
Summary of "Design Patterns Learned in Java Language (Multithread Edition)" (Part 2)
Summary of "Design Patterns Learned in Java Language (Multithread Edition)" (Part 1)
Summary of "Design Patterns Learned in Java Language (Multithread Edition)" (Part 11)
Summary of "Design Patterns Learned in Java Language (Multithread Edition)" (Part 12)
[Java11] Stream Summary -Advantages of Stream-
[Java] Summary of regular expressions
[Java] Summary of operators (operator)
Summary of Java language basics
[Java] Summary of for statements
Summary of Java Math class
[Java] Summary of control syntax
Summary of java error processing
[Java] Summary of mathematical operations
[For beginners] Summary of java constructor
Summary of [Java silver study] package
Summary of object-oriented programming using Java
[Java Silver] Summary of access modifier points
Summary of in-house newcomer study session [Java]
Java knowledge summary
Java Generics Summary
Java design pattern
[java] Summary of how to handle char
Summary of changes other than JEP of Java10
[Java] Personal summary of conditional statements (basic)
Java 8 documentation summary
[Java] [Maven3] Summary of how to use Maven3
Java Summary of frequently searched type conversions
Java 11 document summary
Summary of Java Math.random and import (Calendar)
[java] Summary of how to handle character strings
Summary of Java environment settings for myself [mac]
[Java] Personal summary of classes and methods (basic)
[Java] Summary of how to abbreviate lambda expressions
Expired collection of java
Java 12 new feature summary
[Java] Significance of serialVersionUID
[Summary] Java environment preparation
effective java 3rd summary
NIO.2 review of java
Review of java Shilber
Java 13 new feature summary
Summary of OpenJDK sources
Summary of strong parameters
java --Unification of comments
Summary of jar files
Introduction to design patterns (introduction)
Java static [Personal summary]
History of Java annotation
Summary of information security
Summary of using FragmentArgs
java (merits of polymorphism)
Thread safe summary ~ Java ~