23 Kinds of design patterns and 7 principles __java in Java

Source: Internet
Author: User
23 Design Patterns and 7 major principles in Java Create type Mode 5

Abstract Factory mode (abstract Factory pattern): Provides an interface for creating a family of related or dependent objects without specifying a specific class.

Generator mode (Builder pattern): Encapsulates a product's construction process using the builder pattern and allows you to construct it in steps. The construction of a complex object is separated from its representation, allowing the same build process to create different representations.

Factory mode (factory method pattern): Defines an interface for creating objects, but subclasses decide which class to instantiate. The factory method lets classes defer instantiation to subclasses.

Prototype mode (prototype pattern): Use prototype mode when creating an instance of a given class that is expensive or complex.

Singleton mode (Singleton pattern): Ensures that a class has only one instance and provides a global access point. Structured Mode 7

Adapter mode (Adapter pattern): Converts the interface of a class into another interface that the customer expects. Adapters allow classes that are incompatible with the original interface to work seamlessly. The object adapter uses a combination, and the class adapter uses multiple inheritance.

Bridging pattern: Use bridging mode to allow implementations and abstractions to be changed independently by placing them in two different class levels.

Combined mode (composite pattern): Allows you to combine objects into a tree structure to represent the "whole/part" hierarchy. A combination enables customers to work with individual objects and groups of objects in a consistent way.

Decorator mode (decorator pattern): Dynamically attaching responsibilities to objects, and to extend functionality, adorners provide more flexible alternatives than inheritance.

Facade Pattern: Provides a unified interface for accessing a group of interfaces in a subsystem. The appearance defines a high-level interface that makes the subsystem easier to use.

Hengyuan mode (Flyweight pattern): If you want an instance of a class to be used to provide many "virtual instances", use the fly pattern.

Proxy pattern: Provides an alias or placeholder for another object to control access to the object. Behavioral Patterns

Responsibility chain mode (Chain of responsibility pattern): You can create a chain of objects for a request through the chain of responsibilities. Each object checks the request and processes it, or passes it to the next object in the chain.

Command pattern: Closes a request into an object to parameterize other objects with different requests, queues, or logs. The command mode also supports revocable operations.

Interpreter mode (interpreter pattern): Creates an interpreter for a language using the interpreter pattern.

Iterator mode (iterator pattern): Provides a way to sequentially access individual elements of an aggregation object without exposing its internal representation.

Mediator mode (mediator pattern): Use the mediator pattern to centralize complex communication and control between related objects.

Memo Mode (Memento pattern): You use Memo mode when you want the object to return to its previous state (for example, if your user requests "undo").

Observer mode (Observer pattern): Defines a one-to-many dependency between objects, so that when an object changes state, objects that depend on it are notified and automatically updated.

State pattern: Allows an object to change its behavior as the internal state changes, and the object looks as if it had changed its class.

Policy mode (strategy pattern): Defines the algorithm family, respectively, to be closed, so that they can be replaced, this mode makes the change of algorithm independent of the client using the algorithm.

Template method Mode (Template pattern): Defines the skeleton of an algorithm in one method and delays some steps into subclasses. Template methods allow subclasses to redefine certain steps in an algorithm without changing the structure of the algorithm.

Visitor Mode (visitor pattern): When you want to add new capabilities to a combination of objects, and encapsulation is not important, use the visitor pattern. the relationship between design patterns

Seven major design principles:

Single duty principle (Responsibility principle, SRP):

A class is responsible for a responsibility.

Richter Replacement principle (Liskov substitution principle, LSP):

Inherit and derive the rule.

Dependency inversion principle (dependence inversion principle, DIP):

High-level modules should not rely on low-level modules, both of which should rely on their abstraction; abstractions should not rely on detail; detail should rely on abstraction.
That is, programming against the interface, not programming for implementation.

Interface isolation principles (Interface segregation principle, ISP):

Set up a single interface, do not create a large bloated interface, as far as possible to refine the interface, the interface in the method as little as possible.

Dimitri (Law of demeter/least knowledge Principle, LOD/LKP):

Also known as the minimum knowledge principle, a software entity should interact with other entities as little as possible
In layman's terms, a class should know the least about the classes it needs to be coupled or invoked. Low coupling, cohesion well-structured classes poly.

Opening and closing principles (Open Close principle, OCP):

A software entity such as a class. Modules and functions should be open to extensions and closed for modification.

Combinatorial/Aggregate reuse principles (composition/aggregation reuse principle, CARP):

Use combinations and aggregations to minimize the use of inherited relationships to achieve the principle of reuse.

2016/10/24 Monday 20:52:52 Link:
CSDN Oschina GitHub

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.