Design mode (Golang)

Source: Internet
Author: User
This is a creation in Article, where the information may have evolved or changed.

Six principles of design patterns

Excerpt from 23 design Patterns in Java development

    • 1, open close Principle

      Opening and closing principle is to say to the extension of openness, the modification is closed. When the program needs to expand, can not modify the original code, to achieve a hot plug effect. So a nutshell is: In order to make the program good 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, Richter substitution principle (Liskov Substitution Principle)

      Richter substitution principle (Liskov Substitution Principle LSP) 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. LSP is the cornerstone of inheritance reuse, only if the derived class can replace the base class, the function of the Software unit is not affected, the base class can be really reused, and the derived class can also add new behavior on the basis of the base class. The principle of substitution on the Richter scale is a supplement to the principle of "open-closed". The key step in implementing the "open-close" principle is abstraction. The inheritance of the base class and subclass is the concrete implementation of abstraction, so the principle of the substitution of the Richter scale is the specification of the concrete steps to realize the abstraction. --from Baidu Encyclopedia

    • 3, the dependency reversal principle (dependence inversion Principle)

      This is the basis of the open and close principle, the specific content: true to interface programming, relies on the abstraction and does not depend on the concrete.

    • 4, interface Isolation principle (Interface segregation Principle)

      This principle means that using multiple isolated interfaces is better than using a single interface. or a reduction of the coupling between the class meaning, from here we see, in fact, the design pattern is a software design ideas, from the large software architecture, in order to upgrade and maintenance convenience. So there are multiple occurrences: reducing dependency and reducing coupling.

    • 5, Dimitri rule (least known principle) (Demeter Principle)

      Why do you know the principle at least, that is to say: an entity should be as small as possible interaction with other entities, so that the system function module is relatively independent.

    • 6, the composition multiplexing principle (Composite reuse Principle)

      Principle is to use composition/aggregation as much as possible, rather than using inheritance.

Implementation code

Https://github.com/BPing/golang_design_pattern/tree/master/pattern

    • Create Type C
    • Structural type J
    • Behavioral X
-abstractfactory.Go: Abstract Factory mode (C)-Adapter.Go: Adapter mode (J)-Bridge.Go: Bridging Mode (J)-Builder.Go: Builder mode (C)-chainofresponsibility.Go: Responsibility Chain Mode (X)-Command.Go: Command mode (X)-Composite.Go: Combination mode (J)-Decorator.Go: Adorner mode (J)-facade.Go: Appearance mode (J)-Factory.Go: Factory mode (C)-Flyweight.Go: Enjoy meta mode (J)-interpreter.Go: Interpreter mode (X)-Iterator.Go: Iterator mode (X)-Mediator.Go: Mediator mode (X)-Memento.Go: Memo Mode (X)-Observer.Go: Observer Mode (X)-Prototype.Go: Prototype mode (C)-Proxy.Go: Proxy mode (J)-Singleton.Go: Single case Mode (C)-Singleton2.Go: Single case Mode (C)-State .Go: State mode (X)-strategy.Go: Policy mode (X)-Template.Go: Template mode (X)-Visitor.Go: Visitor Mode (X)

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.