Java design pattern

table of contents

  1. Description of design pattern
  2. Facade pattern
  3. Strategy pattern
  4. Summary of design patterns
  5. References

Design pattern (overview)

--All 23 patterns that a smart person named GoF thought --Target is an object-oriented language --There are several other types ――We are trying to improve extensibility (mainly) by utilizing Java functions. --Inheritance --Polymorphism --Encapsulation, etc. --The excellent veteran thinks like this! A collection of ideas --Not a concrete implementation method --Understand the idea and apply it to your own program


Design pattern (effective usage)

--Apply the idea and reflect it in your source -≠ Implement according to the pattern --Use only when the effect can be expected -≠ Apply as much as possible -≠ Delusion of the effectiveness of the design pattern --If you use it forcibly, it will have the opposite effect. ――Flexibly decide the application according to the situation -≠ Since the application decision was made at the time of design, it will definitely be reflected in the program.


Design pattern (merits and demerits)

merit

  1. Improved extensibility: Utilization of object orientation
  2. Improved reusability: Utilization of object orientation
  3. Improved readability: Utilization of object orientation and common recognition
  4. Improved transmission speed Common recognition

Disadvantages (problems / risks)

  1. Deviation from current thought / mechanism (part)
  2. Reduced productivity
  3. Stick to the pattern
  4. Code complexity
  5. Misunderstandings and unnecessary discussions due to differences in interpretation (because it is abstract)

Design pattern (utilization timing)

--At the time of class design --At the time of refactoring --At the time of review --Reduced explanation time to reviewers --Only if both sides know the pattern --At the time of programming investigation --Reduced reading time --Improved prediction accuracy --Only if you know the pattern --When modifying programming


Two patterns to be covered this time

--Pickup from the following viewpoints --Easy to understand --Easy to use --A certain effect can be expected --There is an example around you

  1. Facade pattern
  2. Strategy pattern

Facade pattern (overview)

--Create a class that handles the complicated processing flow on behalf of the client --The client side can perform complicated processing just by calling the Facade class. --Simplified client-side processing --The most commonly used pattern, unknowingly specified to some extent --Very useful for refactoring


Facade pattern (utilization conditions)

--It is necessary to call various classes in a series of processes --It is a general process called by many clients.


Facade pattern (characters)


Facade pattern (image)

図1.png


Facade pattern (merits and demerits)

merit

  1. Improved readability by simplifying the client
  2. Simplification of addition / correction / deletion of processing
  3. Simplified addition / deletion of clients

Demerit

  1. Unnecessary Facade class mass production

Facade pattern (summary)

--Collect complicated processing in one class --Easy to add processing on the client side ――It is relatively easy to apply --If you do not narrow down the usage, useless classes will increase and it will have the opposite effect.


Strategy pattern (overview)

--Subclass the part where processing is switched by conditional branching --Minimum addition to existing source when conditions increase --Very similar to the State pattern


Strategy pattern (characters)


Strategy pattern (utilization conditions)

--Similar processing is called by conditional branching --Conditions are expected to increase or decrease in the future


Strategy pattern (image / not used)

図2.png


Strategy pattern (when using image)

図3.png


Strategy pattern (merits and demerits)

merit

  1. Clarified range of influence when adding processing class
  2. To not modify existing processing
  3. Easy to understand the processing of the entire program

Disadvantages (risks)

  1. Code complexity due to unreasonable application

Strategy pattern (summary)

--Used when similar processing runs in conditional branching --The range of influence of existing sources can be narrowed down --Slightly more cumbersome and complicated than Facade --If no additional processing is expected, the effort is greater


Design pattern (summary)

--Leverage object orientation for extensibility and reusability --Improves readability (sometimes) ――Apply the idea instead of using it as it is --Combination is also possible ――With 〇〇 pattern! Communication is quick and easy if you can communicate with just ――Since the original is rough, there is a difference in interpretation ――Some of the books I read this time had different interpretations. --If you overdo it, it is a waste of labor and man-hours.


References (honorific titles omitted)

--Design patterns learned in Java language --Author: Hiroshi Yuki --Thorough capture of Java design patterns --Author: Japan Software Engineering Co., Ltd. --Refactoring Safely improve existing code --Author: Martin Fowler --Translation: Kiminobu Kodama, Masao Tomono, Akira Hirasawa, Takashi Umezawa --Design patterns learned from case studies --Author: Naoki Fukuda

Recommended Posts

Java design pattern
Java design pattern summary
[Design pattern] Java core library
Design pattern ~ Builder ~
[Java] Strategy pattern
Design pattern ~ Visitor ~
java callback pattern
Design pattern ~ Proxy ~
Design pattern ~ State ~
Design pattern ~ Strategy ~
Design pattern ~ Singleton ~
Design pattern ~ Composite ~
Design pattern (2): Builder
Design pattern (1): AbstractFactory
[Java] Singleton pattern
Design pattern ~ Command ~
Design pattern ~ Iterator ~
Java Design Patterns
Design pattern ~ Facade ~
Design pattern ~ Bridge ~
Design pattern ~ Mediator ~
Design pattern ~ Decorator ~
Design pattern ~ Interpreter ~
Design pattern ~ Observer ~
Design pattern ~ Prototype ~
[Java] Adapter pattern
Design pattern ~ Memento ~
Design pattern ~ Adapter ~
Java beginner design pattern (Factory Method pattern)
Design pattern ~ Flyweight ~
Java pattern memo
Design pattern ~ Factory Method ~
My DAO pattern (Java)
Design pattern ~ Abstract Factory ~
GoF design pattern summary
Design pattern ~ Template Method ~
Builder pattern (Effective Java)
Java Lambda Command Pattern
Java8 Lambda expression & Stream design pattern reconsideration --Command pattern -
Design pattern ~ Chain of Responsibility ~
Java
Enum Strategy pattern in Java
[Java] Draw a simple pattern
Java
Java8 Lambda Expression & Stream Design Pattern Rethinking --Null Object Pattern -
Java8 Lambda expression & Stream design pattern reconsideration --Template Method pattern -
[Java] Summary of design patterns
Rethinking design patterns with Java8 lambda expressions & Stream --Builder pattern -
Java8 Lambda Expression & Stream Design Pattern Rethinking --Chain of Responsibility Pattern -
Ruby design pattern template method pattern memo
C # chewed design pattern: Template Method
Application example of design pattern (No. 1)
JNA (Java Native Access) pattern collection
Design patterns to enjoy with frequently used Java libraries --Factory pattern
Prototype pattern
Java learning (0)
Studying Java ―― 3
[Java] array
Java protected
Memento Pattern
[Java] Annotation