Introduction to 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 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.

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.

Design Pattern Type:

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, we'll also discuss another type of design pattern: the Java EE design pattern.

Six principles of design pattern:

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 this, we need to use interfaces and abstract classes, which we will refer to later in the specific design.

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.

Disclaimer: Content mainly reproduced from the Novice tutorial: Java design mode Introduction

Introduction to 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.