rain1024 / gVim-Pathogen

My Coding Life
http://rain1024.github.io/gVim-Pathogen
2 stars 0 forks source link

Patterns #24

Closed rain1024 closed 10 years ago

rain1024 commented 10 years ago

Abstract Factory

Tags: <creational> image

Code

References

http://www.dofactory.com/javascript-abstract-factory-pattern.aspx http://sourcemaking.com/design_patterns/abstract_factory/cpp/1

rain1024 commented 10 years ago

Builder

Tags: <creational>

image

rain1024 commented 10 years ago

Factory Method

Tags: <creational>

image

References

rain1024 commented 10 years ago

Prototype

Tags: <creational> image

The Prototype pattern specifies the kind of objects to create using a prototypical instance. Prototypes of new products are often built prior to full production, but in this example, the prototype is passive and does not participate in copying itself. The mitotic division of a cell - resulting in two identical cells - is an example of a prototype that plays an active role in copying itself and thus, demonstrates the Prototype pattern. When a cell splits, two cells of identical genotvpe result. In other words, the cell clones itself.

Intent

Rules of thumb

References

rain1024 commented 10 years ago

Singleton

Tags: <creational> image

The Singleton pattern ensures that a class has only one instance and provides a global point of access to that instance. It is named after the singleton set, which is defined to be a set containing one element. The office of the President of the United States is a Singleton. The United States Constitution specifies the means by which a president is elected, limits the term of office, and defines the order of succession. As a result, there can be at most one active president at any given time. Regardless of the personal identity of the active president, the title, "The President of the United States" is a global point of access that identifies the person in the office.

Intent

Consequences and Trade-offs

References

rain1024 commented 10 years ago

Adapter

Tags: <structural>, <wrapper>

image

rain1024 commented 10 years ago

Bridge

Tags: <structural>

image

rain1024 commented 10 years ago

Composite

Tags: <structural>

image

rain1024 commented 10 years ago

Decorator

Tags: <structural>

image

rain1024 commented 10 years ago

Facade

Tags: <structural> <wrapper> image

The Facade defines a unified, higher level interface to a subsystem that makes it easier to use. Consumers encounter a Facade when ordering from a catalog. The consumer calls one number and speaks with a customer service representative. The customer service representative acts as a Facade, providing an interface to the order fulfillment department, the billing department, and the shipping department.

Intent

Consequences & Trade-offs

Reference

rain1024 commented 10 years ago

Flyweight

Tags: <structural> image

The Flyweight uses sharing to support large numbers of objects efficiently. Modern web browsers use this technique to prevent loading same images twice. When browser loads a web page, it traverse through all images on that page. Browser loads all new images from Internet and places them the internal cache. For already loaded images, a flyweight object is created, which has some unique data like position within the page, but everything else is referenced to the cached one.

Intent

Consequences and Trade-offs

References

rain1024 commented 10 years ago

Proxy

Tags: <structural>

rain1024 commented 10 years ago

Chain of responsibility

Tags: <behavioral>, <decouple> image

The Chain of Responsibility pattern avoids coupling the sender of a request to the receiver by giving more than one object a chance to handle the request. ATM use the Chain of Responsibility in money giving mechanism.

Intent

Structure

image

Consequences and Trade-offs

References

rain1024 commented 10 years ago

Command

Tags: <behavioral> image

Intent

Code

javascript

carManager.execute( "arrangeViewing", "Ferrari", "14523" );
carManager.execute( "requestInfo", "Ford Mondeo", "54323" );
carManager.execute( "requestInfo", "Ford Escort", "34232" );
carManager.execute( "buyVehicle", "Ford Escort", "34232" );

Reference

rain1024 commented 10 years ago

Interpreter

Tags: <behavioral>

rain1024 commented 10 years ago

Iterator

Tags: <behavioral>

rain1024 commented 10 years ago

Mediator

Tags: <behavioral>, <decouple> image

Intent

Consequences & Tradeoffs

Reference

rain1024 commented 10 years ago

Memento

Tags: <behavioral> image

The Memento captures and externalizes an object's internal state so that the object can later be restored to that state. This pattern is common among do-it-yourself mechanics repairing drum brakes on their cars. The drums are removed from both sides, exposing both the right and left brakes. Only one side is disassembled and the other serves as a Memento of how the brake parts fit together. Only after the job has been completed on one side is the other side disassembled. When the second side is disassembled, the first side acts as the Memento.

Intent

References

rain1024 commented 10 years ago

Observer

Tags: <behavioral>, <state>, <decouple> image

Intent

Structure

image

Subject represents the core (or independent or common or engine) abstraction. Observer represents the variable (or dependent or optional or user interface) abstraction. The Subject prompts the Observer objects to do their thing. Each Observer can call back to the Subject as needed.

Rules of thumb

Reference

rain1024 commented 10 years ago

State

Tags: <behavioral>

rain1024 commented 10 years ago

Strategy

Tags: <behavioral> image

Intent

Check list

  1. Identify an algorithm (i.e. a behavior) that the client would prefer to access through a "flex point".
  2. Specify the signature for that algorithm in an interface.
  3. Bury the alternative implementation details in derived classes.
  4. Clients of the algorithm couple themselves to the interface.

Code

Python

strategy0 = StrategyExample()
strategy1 = StrategyExample(executeReplacement1)
strategy2 = StrategyExample(executeReplacement2)

References

rain1024 commented 10 years ago

Template

Tags: <behavioral>

rain1024 commented 10 years ago

Visitor

Tags: <behavioral>

rain1024 commented 10 years ago

Design Paterns