Awesome go language Design patterns and precedent collection

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

From: http://geek.csdn.net/news/detail/100051

Go language from the advent of the industry's general attention, there have been articles analysis, go is the most likely to change the future of IT technology, one of the top ten languages. The author lists the design patterns and precedent of the Go language, and also makes a detailed classification.

Create pattern

    • Abstract Factory mode: Provides an interface for creating a family of related objects;
    • Builder mode: Use simple objects to build complex objects;
    • Factory method Mode: A factory interface that creates product objects, deferring actual creation to subclasses;
    • Object Pool mode: Instantiates and maintains a set of object instances of the same type;
    • Singleton mode: Restricts instances of classes, guaranteeing that only one instance of a class.

Structural mode

    • Adapter mode: Suitable for another incompatible interface to work together;
    • Bridging mode: The abstraction (abstraction) and the implementation (implementation) decoupling, so that the two can be independent of the change;
    • Compositing mode: organizes objects into trees to describe the relationship of trees;
    • Decoration mode: Adds behavior to a static or dynamic object;
    • Façade (facade) mode: Provides a concise and consistent interface for various types of subsystems (or structures and methods), hides the complexity of subsystems and makes subsystems easier to use;
    • Flyweight mode: the use of sharing technology to effectively support a large number of fine-grained objects;
    • MVC pattern: Is the model-view-controller's abbreviation, divides an application into three interrelated parts, organizes the code with a method of business logic, data, interface display separation, and aggregates the business logic into a part, There is no need to rewrite business logic while improving and customizing the interface and user interaction.
    • Proxy mode: Provides a proxy for other objects to control access to this object.

Behavioral patterns

    • Responsibility Chain mode: Enables multiple objects to have the opportunity to process requests, thus avoiding the coupling between the sender and receiver of the request;
    • Mediation (mediator) mode: Use a Mediation object to encapsulate a series of object interaction behaviors;
    • registration (Registry) mode: tracks all subclasses of a given class;
    • Policy mode: Defines a series of algorithms, encapsulates each algorithm, and allows them to be replaced by each other;
    • template mode: Defines the framework for an algorithm in an operation, and delays some steps into subclasses. The template method pattern allows subclasses to redefine some specific steps of the algorithm without altering the structure of an algorithm;
    • Visitor mode: represents an operation that acts on elements in an object structure. It enables developers to define new actions that act on these elements without changing the individual element classes.

Sync mode

    • Condition variables: A mechanism for synchronizing with global variables shared between threads, consisting of two actions: one thread waits for the condition variable to be set up, and the other thread makes the condition "conditional" (giving the condition a signal);
    • Lock/mutex: Execute mutex to restrict the resource to obtain exclusive access;
    • Monitor mode: The combination mode of mutex and condition variable;
    • Read-write lock mode: it divides the audience of the shared resources into readers and writer, readers only read access to the shared resources, while the writer needs to write to the shared resources;
    • Semaphore: Responsible for coordinating each thread to ensure that they are able to use public resources correctly and rationally.

Parallel mode

    • Bounded Parallelism: An independent task that accomplishes a lot of resource constraints;
    • Broadcast (broadcast): Transfers a message to all receivers at the same time;
    • Synergy (Coroutines): A subroutine that allows the suspension and continuation of execution in a particular place;
    • Generator: Generate a series of values at once;
    • Reactor mode: In an event-driven application, the service request for one or more customers is detached (Demultiplex) and dispatched (dispatch) to the application. Synchronously and sequentially handles multiple service requests that are received at the same time.
    • Parallel (Parallelism): Complete a large number of independent tasks;
    • Producer Consumers: Separation of tasks from task execution;
    • Scheduler (Scheduler): Coordinates task steps.

Message delivery pattern

    • Fan in (fan-in): The module directly calls the number of superior modules, like a funnel-type to work;
    • Fanout (fan-out): The number of sub-modules directly called by the module;
    • Futures & Promises: Play a placeholder role, and use the unknown results for synchronization;
    • Publish/subscribe: Passing information to subscribers;
    • Push & Pull: Distributes messages from one pipeline to multiple people.

Stable mode

    • Bulkheads: Implement fault containment principles, such as preventing cascading failures;
    • Circuit Breaker (circuit-breaker) mode: A request to stop a flow when a request is likely to fail;
    • Due Date (Deadline): Once the response is slowed, the client is allowed to stop a waiting response;
    • Fail-fast mechanism: A set of error detection mechanisms. The fail-fast mechanism is likely to occur when multiple threads change the structure of a collection.
    • Handshaking: If a component's unreachable request is denied, ask if it can take more load;
    • Steady state (Steady-state): To accumulate one resource for each service, other services must reclaim these resources;

Anatomy mode

    • Timing Functions: Functions for packing and executing logs;

Precedent

    • Functional Options: Allows you to create clean APIs and habitual overloads for default values;

Anti-pattern

    • Cascading failure: A certain part of a system error, and the related to the subordinate also with the failure, resulting in a domino effect.


Related Article

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.