Introduction to Java Design Patterns 0--Design Patterns

Source: Internet
Author: User

Design patterns are a set of reusable, most known, categorized purposes, code design experience Summary. Design patterns are used in order to reuse code, make code easier for others to understand, and ensure code reliability.

The origins of design patterns

The design pattern of software field originates from architecture.

In 1977, architectural master Alexander published the book "A Pattern language:towns, Building, construction". Influenced by the writings of Alexander, Kent Beck and Ward Cunningham published a paper at an object-oriented meeting in 1987: Using patterns in object-oriented programming.

Classification of design Patterns

Gof's writings

At present, the most influential book in the field of design patterns is the work published by Erich Gamma, Richard Helm, Ralph Johnson and John Vlissides in 1994: "Design patterns:elements of reusable object-oriented Software (the "design mode: The basic principle of reusable object-oriented software" or "design mode"), the book was nicknamed Gof (Gang of four) by the majority of the readers, Gof is considered a must-read for learning design patterns, and the book has been recognized as a cornerstone in the field of design patterns.

Some basic principles of object-oriented

1. For abstract principles

When designing a class, do not let the class target a specific class, but instead target an abstract class or interface.

For example: Define a cylinder with a triangular bottom face

2. Open-Close principle

The design should be open to extensions and closed for modification.

If your design adheres to the open-close principle, then this design must be maintainable, since adding new modules to the design does not necessarily modify the core modules in the design.

3. High cohesion-low coupling principle

If a method in a class is a set of related behaviors, it is said that the class is high cohesion, and vice versa is called low cohesion.

The so-called low-coupling is to try not to allow a class to contain too many references to instances of other classes, to avoid modifying part of the system to affect other parts.

Learning design patterns can not only enable us to use these successful models, but more importantly, we can understand the object-oriented design concept more deeply, and it is very helpful for us to use object-oriented language to solve the problems in the design.

Rational Use mode

1. Use correctly; 2. Avoid dogma; 3. Pattern Mining

Introduction to Java Design Patterns 0--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.