Java Design Patterns

Source: Internet
Author: User

Introduction to Design Patterns

Design patterns represent best practices and are often used by experienced object-oriented software developers. Design pattern is a solution to the general problems faced by software developers in the process of software development. These solutions are summed up by many software developers over a long period of trial and error.

Design patterns are a set of reusable, most known, categorized purposes, code design experience Summary. Design patterns are used to reuse code, make code easier for others to understand, and ensure code reliability. There is no doubt that design patterns in others in the system are multi-win, design patterns so that code is truly engineering, design patterns are the cornerstone of software engineering, like a block of bricks and tiles in the building. The rational use of design patterns in the project can solve many problems perfectly, each of which has corresponding principles in reality, each of which describes a recurring problem around us, and the core solution to the problem, which is why design patterns can be widely used.

Two main uses of design patterns in software development.

A common platform for developers

Design patterns provide a standard terminology system and are specific to specific scenarios. For example, a singleton design pattern means using a single object so that all developers who are familiar with the singleton design pattern can use a single object and can tell each other in this way that the program is using singleton mode.

The best practice

Design patterns have evolved over a long period of time, providing the best solution for general problems that are encountered during software development. Learning these patterns helps inexperienced developers learn software designs in a simple and quick way.

Types of Design Patterns

According to the design pattern of the reference book designed patterns-elements of reusable object-oriented software (Chinese translation: Design Patterns-Reusable object-oriented software elements) mentioned in a total of 23 Design patterns. These patterns can be categorized into three main categories: the creation pattern (creational Patterns), the structural pattern (Structural Patterns), and the Behavioral pattern (behavioral Patterns). Of course, there is another type of design pattern: the Java EE design pattern.

Serial Number Patterns & Descriptions include
1 Create pattern
These design patterns provide a way to hide the creation logic while creating the object, rather than instantiating the object directly with the new operator. This allows the program to be more flexible when judging which objects need to be created for a given instance.
  • Factory mode (Factory pattern)
  • Abstract Factory mode (Factory pattern)
  • Singleton mode (Singleton pattern)
  • Builders Mode (builder pattern)
  • Prototype mode (Prototype pattern)
2 Structural mode
These design patterns focus on the combination of classes and objects. The concept of inheritance is used to combine interfaces and define how composite objects acquire new functionality.
  • Adapter mode (Adapter pattern)
  • Bridging mode (bridge pattern)
  • Filter mode (filter, Criteria pattern)
  • Combination mode (Composite pattern)
  • Adorner mode (Decorator pattern)
  • Appearance mode (facade pattern)
  • Enjoy meta mode (Flyweight pattern)
  • Agent mode (proxy pattern)
3 Behavioral patterns
These design patterns pay particular attention to communication between objects.
  • Responsibility chain mode (Chain of Responsibility pattern)
  • Command pattern
  • Interpreter mode (interpreter pattern)
  • Iterator mode (Iterator pattern)
  • Mediator mode (mediator pattern)
  • Memo Mode (Memento pattern)
  • Observer mode (Observer pattern)
  • Status mode (state pattern)
  • Null object pattern (null-type-pattern)
  • Policy mode (strategy pattern)
  • Template pattern
  • Visitor Mode (Visitor pattern)
4 Java EE mode
These design patterns pay particular attention to the presentation layer. These patterns are identified by Sun Java Center.
  • MVC patterns (MVC pattern)
  • Business representative model (Delegate pattern)
  • Combined entity mode (Composite entities pattern)
  • Data Access Object pattern
  • Front-end Controller mode (Front controllers pattern)
  • Interceptor filter pattern (intercepting)
  • Service Locator mode (Locator pattern)
  • Transfer object Pattern (Transfer)

Six principles of design patterns

1. Opening and closing principle (Open Close Principle)

The opening and closing principle means: open for expansion, close for modification . When the program needs to expand, can not modify the original code, to achieve a hot plug effect. In short, it is to make the program extensibility, easy to maintain and upgrade. To achieve such an effect, we need to use interfaces and abstract classes.

2. The principle of substitution on the Richter scale (Liskov Substitution Principle)

The principle of substitution on the Richter scale is one of the basic principles of object oriented design. The Richter substitution principle says that where any base class can appear, subclasses must be able to appear. The LSP is the cornerstone of inheritance reuse, and the base class can be reused only if the derived class is able to replace the base class and the functionality of the Software Unit is not affected, and the derived class can also add new behavior on the base class. The principle of substitution of the Richter scale is complementary to the principle of closure. The key step of realizing the opening and closing principle is abstraction, and the inheritance relation of the base class and subclass is the concrete realization of abstraction, so the principle of substitution of the Richter scale is the specification of the concrete steps to realize abstraction.

3. Dependence reversal principle (dependence inversion Principle)

This principle is the basis of the open-close principle, the specific content: programming for the interface, relying on abstraction and not dependent on the specific.

4. Interface Isolation principle (Interface segregation Principle)

This principle means that using multiple isolated interfaces is better than using a single interface. It also has another meaning: to reduce the degree of coupling between classes. Thus, in fact, the design pattern is from the large software architecture, easy to upgrade and maintain the software design ideas, it emphasizes the reduction of dependence, reduce coupling.

5, Dimitri Law, also known as least know the principle (Demeter Principle)

The least known principle is that an entity should interact with other entities as little as possible, making the system function modules relatively independent.

6. Synthetic multiplexing principles (Composite reuse Principle)

The synthetic reuse principle refers to the use of synthetic/aggregated methods rather than inheritance.

Java Design Patterns

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.