The Java Design Patterns series, for now, makes design patterns so simple.
Java design patterns series of articles
- Java Design Patterns (I) Adapter Patterns
- Java Design Patterns (2) The Builder Pattern
- Java Design Pattern (3) singleton Pattern
- Java Design Patterns (4) Proxy Patterns
- .
Blog content will be updated at the same time as the code. Updated: aug 23, 2018 11:26:00 ↓↓
More information is available here > > — > — > – – – – >? -? ↗ ↗
Overview of Design patterns
1.1 the introduction
Design patterns are formal best practices that programmers can use. Solve common application or system design problems. Learning these patterns helps inexperienced developers learn software design in an easy and quick way.
1.2 introduction
Design patterns represent best practices and are generally adopted by experienced object-oriented software developers. Design pattern is a solution to the common problems faced by software developers during software development. These solutions have been developed by numerous software developers over a long period of trial and error.
A design pattern is a set of repeated, well-known, catalogued code design lessons. Design patterns are used to reuse code, make it easier for others to understand, and ensure code reliability. There is no doubt that design patterns are a win-win for yourself, others and systems. Design patterns make coding truly engineering. Design patterns are the cornerstones of software engineering, like the bricks and stones of a mansion. The rational application of design patterns in projects can perfectly solve many problems. Each pattern has its corresponding principle in reality, and each pattern describes a recurring problem around us, as well as the core solution of the problem, which is also the reason why design patterns can be widely used.
# Design principles
All design should be as simple as possible, should start from KISS, YAGNI principle, do some simple things, complex things and patterns, when it is appropriate to reference, pay attention to extensibility.
The YAGNI principle stands for "You aren't gonna Need it."
The KISS principle is short for Keep It Simple,Stupid. It refers to the principle of simplicity in design
Keep everything simple, get rid of everything you don’t need, actively refactor when you do, and iterate quickly.
Type of design pattern
The serial number | Patterns & Types | Contains the content |
---|---|---|
1 | Creator mode:
These design patterns provide a way to hide the creation logic while creating objects, rather than instantiating objects directly with new operators. This gives the program more flexibility in deciding which objects to create for a given instance. |
Factory Pattern |
Abstract Factory Pattern | ||
Singleton Pattern | ||
Builder Pattern | ||
Prototype Pattern | ||
2 | Structural mode:
These design patterns focus on combinations of classes and objects. The concept of inheritance is used to combine interfaces and define how composite objects acquire new functionality. |
Adapter Pattern |
Bridge Pattern | ||
Filter Pattern (Filter, Criteria Pattern) | ||
Composite Pattern | ||
Decorator Pattern | ||
Facade Pattern | ||
Flyweight Pattern | ||
Proxy Pattern | ||
3 | Behavioral patterns:
These design patterns are particularly concerned with communication between objects. |
Chain of Responsibility Pattern |
Command Pattern | ||
Interpreter Pattern | ||
Iterator Pattern | ||
Mediator Pattern | ||
Memento Pattern | ||
Observer Pattern | ||
State Pattern | ||
Null Object Pattern | ||
Strategy Pattern | ||
Template Pattern | ||
Visitor Pattern | ||
4 | J2EE patterns:
These design patterns pay particular attention to the presentation layer. These patterns were identified by the Sun Java Center. |
MVC Pattern (MVC Pattern) |
Business Delegate Pattern | ||
Composite Entity Pattern | ||
Data Access Object Pattern | ||
Front Controller Pattern | ||
Intercepting Filter Pattern | ||
Service Locator Pattern | ||
Transfer Object Pattern |
# Six principles of design
1. Open Close Principle
The open and closed principle refers to: open for extension, closed for modification, when the program needs to be extended, can not modify the source code, need to achieve a hot plug effect. In order to make the program extensible, easy to maintain and upgrade, we need to use interfaces and abstract classes.
2. Liskov Substitution Principle LSP
Richter’s substitution principle is one of the principles of object-oriented design. Richter’s substitution principle states that wherever a base class can appear, a subclass must appear. LSP is the foundation of inheritance reuse. The base class can be reused only when the derived class can replace the base class and the function of the software unit is not affected, and the derived class can add new behavior to the base class. Richter’s substitution principle is a complement to the open – close principle. The key to implementing the open close principle is abstraction. The inheritance relationship between base class and subclass is the concrete implementation of abstraction. So the Richter substitution principle is a specification of the steps to achieve abstraction.
3. Dependence Inversion Principle
This principle is the basis of the open closed principle, which is to program for interfaces and rely on abstractions rather than concrete implementations.
4. Interface Segregation Principle
This principle means that it is better to use multiple isolated interfaces than a single one. Reduce coupling between classes. Through this design principle, we know that design mode is the software design idea that starts from large-scale software architecture, and then upgrades and maintains. It emphasizes reducing dependence and coupling.
5. Demeter Principle
The least known principle means that an entity should interact with other entities as little as possible, so that the functional modules of the system are independent of each other.
2. Composite Reuse Principle
The principle of composite reuse is to use composition/aggregation rather than inheritance whenever possible.
Refer to the content
- Java implements design patterns
- Design patterns | novice tutorial
- KISS&YAGNI