JAVA design patterns --- Overview articles

First, design patterns (Design Pattern):

  1. The concept of design patterns  

    Predecessors is a summary of the code development experience, it is to solve the problem of a series of specific routines. It is not defined syntax, but a set of solutions can be used to improve code reusability, maintainability, readability, robustness and security. Use design patterns to reusable code, make the code easier to understand others, to ensure the reliability of the code.

   2. meaningful learning design patterns

   The nature of the actual design pattern using object-oriented design principles, a thorough understanding of class relationships encapsulation, inheritance and polymorphism combinations and classes and relations. Proper use of design patterns has the following advantages:

  • You can improve thinking skills, programming skills and design capabilities programmer.
  • Make programming more standardized, more engineering preparation of the code, greatly improving the efficiency of software development, thus shortening the development cycle of the software.
  • The design code reusability high, readable, high reliability, good flexibility and maintainability.

 

Second, the design pattern classification :

JAVA design patterns in a total of 23 species, a total can be divided into three categories: 

  Create a schema, a total of five categories: factory method pattern, abstract factory pattern, singleton mode, the builder pattern, prototype model

  Structural model, a total of seven kinds: adapter mode, decorator mode, proxy mode, the appearance mode, bridge mode, combination mode, Flyweight.

  Behavioral patterns, a total of eleven kinds: Strategy pattern, the template method pattern, observer mode, iterator pattern, the responsibility chain mode, command mode, the memo mode state mode, the visitor pattern, intermediary model to explain the mode.

  In fact, there are two types: concurrency pattern and thread pool mode.

Third, the six principles of design patterns:

  General principle - the principle of opening and closing

    Open for extension, closed for modification. When the program needs to expand, not to modify the original code, but to expand the existing code. Summarized in one sentence: To make good, easy to maintain and upgrade the extension of the program.

  1. Single Responsibility Principle

    The reason there is not more than one class leads to change, which means that each class should implement a single responsibility, otherwise it should split the class

  2, Richter substitution principle (Liskov Substitution Principle)

    Richter substitution principle (Liskov Substitution Principle LSP) is one of the basic principles of object-oriented design. Richter said that the principle of replacing, where any base class can appear, sub-class will be able to appear. LSP is inherited cornerstone multiplexed only when the derived class can replace the base class, the software unit of functionality is not affected, the base class can really be reused, derived class can add new behavior on the basis of the base class on . Richter substitution principle is - to add "on-off" principle. To achieve "open - closed" principle is a key step in abstraction. Richter replaced in principle, sub-categories and try not to override the parent class method overloading. Because the parent class represents a well-defined structure, through this interface specifications to interact with the outside world, the subclass should not just destroy it.

  3. Dependency Inversion Principle (Dependence Inversion Principle)

    Oriented programming interface, dependent on the abstract does not depend on the specific. When used in a specific class when writing code, not, and upper interface to interact with the specific type of interaction with the specific class.

  4, the interface segregation principle (Interface Segregation Principle)

    Each interface does not exist in subclasses, but not by the method to be implemented, if otherwise, the interface will be necessary to split. A plurality of interface isolation, than using a single interface (s interfaces to a set of interface methods) is better.

  5, the Law of Demeter (the least known principle) (Demeter Principle)

    Why call least known principles, that is to say: an entity should minimize the interaction between the entity and the other, such that the independent function modules.

  6, the synthesis of multiplexing principles (Composite Reuse Principle)

    Principle is to use the synthetic polymeric info / instead of inheritance.

Fourth, written in the last

  Benpian is classified JAVA design patterns and principles made a general presentation, follow-up blog post, will continue to introduce the specific implementation of each design pattern, we welcome the attention subscription.

  

  

Guess you like

Origin www.cnblogs.com/shi-zhe/p/11600137.html