Proficient in Java design patterns from the first sight of love (1-23)

1. How to use it?

    Design patterns are created to solve problems, a solution. What is your problem determines which design pattern you use. If you don’t have a problem, you just stick to a design pattern. This is nothing to worry about. Your problem is like: 

     Self: Doctor, I am 170cm tall and weigh 60kg. Which of these twenty-three medicines should I take?

     Doctor: Eat your sister, eat brain fragments

2. Three categories:

    There are three design patterns

    2.1 Creation mode: used for producing class objects, similar to new class name();

    2.2 Structural pattern: used to define classes and class relationships, to solve the coupling problem between modules from the structure of the program

    2.3 Behavioral pattern design to assignment of responsibilities between algorithms and objects

    Creation Patterns: Factory, Abstract Factory, Singleton, Builder, Prototype

    Structural Patterns: Adapter, Decorator, Proxy, Facade, Bridge, Composition, Flyweight

    Behavioral Patterns: Strategy, Template, Observer, Iteration, Chain of Responsibility, Command, Memo, State, Visitor, Mediation, Interpreter

3. Proficient in the list of design patterns (basically every blog corresponds to the actual application scenario in the project)

Singleton Design Pattern: https://my.oschina.net/mdxlcj/blog/1786451

Factory + Strategy (2 modes): https://my.oschina.net/mdxlcj/blog/1787501

Abstract factory + template (2 modes): https://my.oschina.net/mdxlcj/blog/1794088

Builder: https://my.oschina.net/mdxlcj/blog/1794236

Prototype: https://my.oschina.net/mdxlcj/blog/1789168

Adapter: https://my.oschina.net/mdxlcj/blog/1798076

Decoration: https://my.oschina.net/mdxlcj/blog/1797495

Agent: https://my.oschina.net/mdxlcj/blog/1786848

Bridging: https://my.oschina.net/mdxlcj/blog/1799639

Appearance: https://my.oschina.net/mdxlcj/blog/1799809

Combination: https://my.oschina.net/mdxlcj/blog/1799989

Flyweight: https://my.oschina.net/mdxlcj/blog/1800607

Filter: https://my.oschina.net/mdxlcj/blog/1800850

Chain of Responsibility: https://my.oschina.net/mdxlcj/blog/1801027

Command: https://my.oschina.net/mdxlcj/blog/1801137

Intermediary: https://my.oschina.net/mdxlcj/blog/1801391

Personally feel useless design patterns, design patterns that can be completed directly in the project with business logic:

Iterator design pattern: only used in java collection classes, not needed in the project

Interpreter Design Patterns: Useless

Memo design pattern: similar to the rollback design pattern, useless, just colne directly

Observer design pattern: useless, business logic can be written

State design pattern: useless, business logic code can be written

Visitor design pattern: useless, business logic can be written

 

4. Summary

    Knowing design patterns is not the same as knowing how to use design patterns. Don't backfire. Write design patterns for the sake of writing design patterns.

    As an example:

    Design mode is a solution. You have a million troops, and the opponent has 100 people. The strength gap is very large. You can just let them rush up and kill them directly, but you want to use an ambush formation (the formation method is equivalent to A solution, a design pattern) to kill the enemy, although the results are the same, but don't you think it's a hassle to take off your pants and fart.

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324939194&siteId=291194637
Recommended