提交 b3e4e8a4 编写于 作者: N Narendra Pathai

Work on #226, #213, added references of Gang Of Four to all GoF patterns,...

Work on #226, #213, added references of Gang Of Four to all GoF patterns, added tag for Gang Of Four, added difficulty tags to some of them
上级 dd0fcea0
......@@ -4,7 +4,9 @@ title: Abstract Factory
folder: abstract-factory
permalink: /patterns/abstract-factory/
categories: Creational
tags: Java
tags:
- Java
- Gang Of Four
---
**Intent:** Provide an interface for creating families of related or dependent
......@@ -22,3 +24,7 @@ objects without specifying their concrete classes.
**Real world examples:**
* [javax.xml.parsers.DocumentBuilderFactory](http://docs.oracle.com/javase/8/docs/api/javax/xml/parsers/DocumentBuilderFactory.html)
**Credits**
* [Design Patterns: Elements of Reusable Object-Oriented Software](http://www.amazon.com/Design-Patterns-Elements-Reusable-Object-Oriented/dp/0201633612)
......@@ -4,7 +4,9 @@ title: Adapter
folder: adapter
permalink: /patterns/adapter/
categories: Structural
tags: Java
tags:
- Java
- Gang Of Four
---
**Intent:** Convert the interface of a class into another interface the clients
......@@ -22,3 +24,7 @@ incompatible interfaces.
**Real world examples:**
* [java.util.Arrays#asList()](http://docs.oracle.com/javase/8/docs/api/java/util/Arrays.html#asList%28T...%29)
**Credits**
* [Design Patterns: Elements of Reusable Object-Oriented Software](http://www.amazon.com/Design-Patterns-Elements-Reusable-Object-Oriented/dp/0201633612)
......@@ -4,7 +4,9 @@ title: Bridge
folder: bridge
permalink: /patterns/bridge/
categories: Structural
tags: Java
tags:
- Java
- Gang Of Four
---
**Intent:** Decouple an abstraction from its implementation so that the two can
......@@ -20,3 +22,7 @@ vary independently.
* changes in the implementation of an abstraction should have no impact on clients; that is, their code should not have to be recompiled.
* you have a proliferation of classes. Such a class hierarchy indicates the need for splitting an object into two parts. Rumbaugh uses the term "nested generalizations" to refer to such class hierarchies
* you want to share an implementation among multiple objects (perhaps using reference counting), and this fact should be hidden from the client. A simple example is Coplien's String class, in which multiple objects can share the same string representation.
**Credits**
* [Design Patterns: Elements of Reusable Object-Oriented Software](http://www.amazon.com/Design-Patterns-Elements-Reusable-Object-Oriented/dp/0201633612)
......@@ -4,7 +4,9 @@ title: Builder
folder: builder
permalink: /patterns/builder/
categories: Creational
tags: Java
tags:
- Java
- Gang Of Four
---
**Intent:** Separate the construction of a complex object from its
......@@ -22,3 +24,7 @@ representations.
* [java.lang.StringBuilder](http://docs.oracle.com/javase/8/docs/api/java/lang/StringBuilder.html)
* [Apache Camel builders](https://github.com/apache/camel/tree/0e195428ee04531be27a0b659005e3aa8d159d23/camel-core/src/main/java/org/apache/camel/builder)
**Credits**
* [Design Patterns: Elements of Reusable Object-Oriented Software](http://www.amazon.com/Design-Patterns-Elements-Reusable-Object-Oriented/dp/0201633612)
......@@ -4,7 +4,9 @@ title: Chain of responsibility
folder: chain
permalink: /patterns/chain/
categories: Behavioral
tags: Java
tags:
- Java
- Gang Of Four
---
**Intent:** Avoid coupling the sender of a request to its receiver by giving
......@@ -23,3 +25,7 @@ objects and pass the request along the chain until an object handles it.
* [java.util.logging.Logger#log()](http://docs.oracle.com/javase/8/docs/api/java/util/logging/Logger.html#log%28java.util.logging.Level,%20java.lang.String%29)
* [Apache Commons Chain](https://commons.apache.org/proper/commons-chain/index.html)
**Credits**
* [Design Patterns: Elements of Reusable Object-Oriented Software](http://www.amazon.com/Design-Patterns-Elements-Reusable-Object-Oriented/dp/0201633612)
......@@ -4,7 +4,9 @@ title: Command
folder: command
permalink: /patterns/command/
categories: Behavioral
tags: Java
tags:
- Java
- Gang Of Four
---
**Intent:** Encapsulate a request as an object, thereby letting you
......@@ -30,3 +32,7 @@ support undoable operations.
**Real world examples:**
* [java.lang.Runnable](http://docs.oracle.com/javase/8/docs/api/java/lang/Runnable.html)
**Credits**
* [Design Patterns: Elements of Reusable Object-Oriented Software](http://www.amazon.com/Design-Patterns-Elements-Reusable-Object-Oriented/dp/0201633612)
......@@ -4,7 +4,9 @@ title: Composite
folder: composite
permalink: /patterns/composite/
categories: Structural
tags: Java
tags:
- Java
- Gang Of Four
---
**Intent:** Compose objects into tree structures to represent part-whole
......@@ -22,3 +24,7 @@ of objects uniformly.
* [java.awt.Container](http://docs.oracle.com/javase/8/docs/api/java/awt/Container.html) and [java.awt.Component](http://docs.oracle.com/javase/8/docs/api/java/awt/Component.html)
* [Apache Wicket](https://github.com/apache/wicket) component tree, see [Component](https://github.com/apache/wicket/blob/91e154702ab1ff3481ef6cbb04c6044814b7e130/wicket-core/src/main/java/org/apache/wicket/Component.java) and [MarkupContainer](https://github.com/apache/wicket/blob/b60ec64d0b50a611a9549809c9ab216f0ffa3ae3/wicket-core/src/main/java/org/apache/wicket/MarkupContainer.java)
**Credits**
* [Design Patterns: Elements of Reusable Object-Oriented Software](http://www.amazon.com/Design-Patterns-Elements-Reusable-Object-Oriented/dp/0201633612)
......@@ -4,7 +4,9 @@ title: Decorator
folder: decorator
permalink: /patterns/decorator/
categories: Structural
tags: Java
tags:
- Java
- Gang Of Four
---
**Intent:** Attach additional responsibilities to an object dynamically.
......@@ -18,3 +20,7 @@ functionality.
* to add responsibilities to individual objects dynamically and transparently, that is, without affecting other objects
* for responsibilities that can be withdrawn
* when extension by subclassing is impractical. Sometimes a large number of independent extensions are possible and would produce an explosion of subclasses to support every combination. Or a class definition may be hidden or otherwise unavailable for subclassing
**Credits**
* [Design Patterns: Elements of Reusable Object-Oriented Software](http://www.amazon.com/Design-Patterns-Elements-Reusable-Object-Oriented/dp/0201633612)
......@@ -4,7 +4,9 @@ title: Facade
folder: facade
permalink: /patterns/facade/
categories: Structural
tags: Java
tags:
- Java
- Gang Of Four
---
**Intent:** Provide a unified interface to a set of interfaces in a subsystem.
......@@ -17,3 +19,7 @@ Facade defines a higher-level interface that makes the subsystem easier to use.
* you want to provide a simple interface to a complex subsystem. Subsystems often get more complex as they evolve. Most patterns, when applied, result in more and smaller classes. This makes the subsystem more reusable and easier to customize, but it also becomes harder to use for clients that don't need to customize it. A facade can provide a simple default view of the subsystem that is good enough for most clients. Only clients needing more customizability will need to look beyond the facade.
* there are many dependencies between clients and the implementation classes of an abstraction. Introduce a facade to decouple the subsystem from clients and other subsystems, thereby promoting subsystem independence and portability.
* you want to layer your subsystems. Use a facade to define an entry point to each subsystem level. If subsystems are dependent, the you can simplify the dependencies between them by making them communicate with each other solely through their facades
**Credits**
* [Design Patterns: Elements of Reusable Object-Oriented Software](http://www.amazon.com/Design-Patterns-Elements-Reusable-Object-Oriented/dp/0201633612)
......@@ -7,6 +7,7 @@ categories: Creational
tags:
- Java
- Difficulty-Beginner
- Gang Of Four
---
**Intent:** Define an interface for creating an object, but let subclasses
......@@ -20,3 +21,7 @@ instantiation to subclasses.
* a class can't anticipate the class of objects it must create
* a class wants its subclasses to specify the objects it creates
* classes delegate responsibility to one of several helper subclasses, and you want to localize the knowledge of which helper subclass is the delegate
**Credits**
* [Design Patterns: Elements of Reusable Object-Oriented Software](http://www.amazon.com/Design-Patterns-Elements-Reusable-Object-Oriented/dp/0201633612)
......@@ -4,7 +4,9 @@ title: Flyweight
folder: flyweight
permalink: /patterns/flyweight/
categories: Structural
tags: Java
tags:
- Java
- Gang Of Four
---
**Intent:** Use sharing to support large numbers of fine-grained objects
......@@ -25,3 +27,7 @@ true
**Real world examples:**
* [java.lang.Integer#valueOf(int)](http://docs.oracle.com/javase/8/docs/api/java/lang/Integer.html#valueOf%28int%29)
**Credits**
* [Design Patterns: Elements of Reusable Object-Oriented Software](http://www.amazon.com/Design-Patterns-Elements-Reusable-Object-Oriented/dp/0201633612)
......@@ -4,7 +4,9 @@ title: Interpreter
folder: interpreter
permalink: /patterns/interpreter/
categories: Behavioral
tags: Java
tags:
- Java
- Gang Of Four
---
**Intent:** Given a language, define a representation for its grammar along
......@@ -19,3 +21,7 @@ trees. The Interpreter pattern works best when
* the grammar is simple. For complex grammars, the class hierarchy for the grammar becomes large and unmanageable. Tools such as parser generators are a better alternative in such cases. They can interpret expressions without building abstract syntax trees, which can save space and possibly time
* efficiency is not a critical concern. The most efficient interpreters are usually not implemented by interpreting parse trees directly but by first translating them into another form. For example, regular expressions are often transformed into state machines. But even then, the translator can be implemented by the Interpreter pattern, so the pattern is still applicable
**Credits**
* [Design Patterns: Elements of Reusable Object-Oriented Software](http://www.amazon.com/Design-Patterns-Elements-Reusable-Object-Oriented/dp/0201633612)
......@@ -4,7 +4,10 @@ title: Iterator
folder: iterator
permalink: /patterns/iterator/
categories: Behavioral
tags: Java
tags:
- Java
- Difficulty-Beginner
- Gang Of Four
---
**Intent:** Provide a way to access the elements of an aggregate object
......@@ -21,3 +24,7 @@ sequentially without exposing its underlying representation.
**Real world examples:**
* [java.util.Iterator](http://docs.oracle.com/javase/8/docs/api/java/util/Iterator.html)
**Credits**
* [Design Patterns: Elements of Reusable Object-Oriented Software](http://www.amazon.com/Design-Patterns-Elements-Reusable-Object-Oriented/dp/0201633612)
......@@ -4,7 +4,10 @@ title: Mediator
folder: mediator
permalink: /patterns/mediator/
categories: Behavioral
tags: Java
tags:
- Java
- Gang Of Four
- Difficulty-Intermediate
---
**Intent:** Define an object that encapsulates how a set of objects interact.
......@@ -18,3 +21,7 @@ other explicitly, and it lets you vary their interaction independently.
* a set of objects communicate in well-defined but complex ways. The resulting interdependencies are unstructured and difficult to understand
* reusing an object is difficult because it refers to and communicates with many other objects
* a behavior that's distributed between several classes should be customizable without a lot of subclassing
**Credits**
* [Design Patterns: Elements of Reusable Object-Oriented Software](http://www.amazon.com/Design-Patterns-Elements-Reusable-Object-Oriented/dp/0201633612)
......@@ -4,7 +4,9 @@ title: Memento
folder: memento
permalink: /patterns/memento/
categories: Behavioral
tags: Java
tags:
- Java
- Gang Of Four
---
**Intent:** Without violating encapsulation, capture and externalize an
......@@ -20,3 +22,7 @@ object's internal state so that the object can be restored to this state later.
**Real world examples:**
* [java.util.Date](http://docs.oracle.com/javase/8/docs/api/java/util/Date.html)
**Credits**
* [Design Patterns: Elements of Reusable Object-Oriented Software](http://www.amazon.com/Design-Patterns-Elements-Reusable-Object-Oriented/dp/0201633612)
......@@ -4,7 +4,10 @@ title: Observer
folder: observer
permalink: /patterns/observer/
categories: Behavioral
tags: Java
tags:
- Java
- Difficulty-Beginner
- Gang Of Four
---
**Intent:** Define a one-to-many dependency between objects so that when one
......@@ -26,3 +29,7 @@ automatically.
**Real world examples:**
* [java.util.Observer](http://docs.oracle.com/javase/8/docs/api/java/util/Observer.html)
**Credits**
* [Design Patterns: Elements of Reusable Object-Oriented Software](http://www.amazon.com/Design-Patterns-Elements-Reusable-Object-Oriented/dp/0201633612)
......@@ -4,7 +4,9 @@ title: Prototype
folder: prototype
permalink: /patterns/prototype/
categories: Creational
tags: Java
tags:
- Java
- Gang Of Four
---
**Intent:** Specify the kinds of objects to create using a prototypical
......@@ -21,3 +23,7 @@ instance, and create new objects by copying this prototype.
**Real world examples:**
* [java.lang.Object#clone()](http://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#clone%28%29)
**Credits**
* [Design Patterns: Elements of Reusable Object-Oriented Software](http://www.amazon.com/Design-Patterns-Elements-Reusable-Object-Oriented/dp/0201633612)
......@@ -4,7 +4,10 @@ title: Proxy
folder: proxy
permalink: /patterns/proxy/
categories: Structural
tags: Java
tags:
- Java
- Gang Of Four
- Difficulty-Intermediate
---
**Intent:** Provide a surrogate or placeholder for another object to control
......@@ -32,3 +35,7 @@ are several common situations in which the Proxy pattern is applicable
* [java.lang.reflect.Proxy](http://docs.oracle.com/javase/8/docs/api/java/lang/reflect/Proxy.html)
* [Apache Commons Proxy](https://commons.apache.org/proper/commons-proxy/)
**Credits**
* [Design Patterns: Elements of Reusable Object-Oriented Software](http://www.amazon.com/Design-Patterns-Elements-Reusable-Object-Oriented/dp/0201633612)
......@@ -4,7 +4,10 @@ title: Singleton
folder: singleton
permalink: /patterns/singleton/
categories: Creational
tags: Java
tags:
- Java
- Gang Of Four
- Difficulty-Beginner
---
**Intent:** Ensure a class only has one instance, and provide a global point of
......@@ -26,3 +29,7 @@ access to it.
**Real world examples:**
* [java.lang.Runtime#getRuntime()](http://docs.oracle.com/javase/8/docs/api/java/lang/Runtime.html#getRuntime%28%29)
**Credits**
* [Design Patterns: Elements of Reusable Object-Oriented Software](http://www.amazon.com/Design-Patterns-Elements-Reusable-Object-Oriented/dp/0201633612)
......@@ -4,7 +4,10 @@ title: State
folder: state
permalink: /patterns/state/
categories: Behavioral
tags: Java
tags:
- Java
- Difficulty-Intermediate
- Gang Of Four
---
**Intent:** Allow an object to alter its behavior when its internal state
......@@ -16,3 +19,7 @@ changes. The object will appear to change its class.
* an object's behavior depends on its state, and it must change its behavior at run-time depending on that state
* operations have large, multipart conditional statements that depend on the object's state. This state is usually represented by one or more enumerated constants. Often, several operations will contain this same conditional structure. The State pattern puts each branch of the conditional in a separate class. This lets you treat the object's state as an object in its own right that can vary independently from other objects.
**Credits**
* [Design Patterns: Elements of Reusable Object-Oriented Software](http://www.amazon.com/Design-Patterns-Elements-Reusable-Object-Oriented/dp/0201633612)
......@@ -4,7 +4,10 @@ title: Strategy
folder: strategy
permalink: /patterns/strategy/
categories: Behavioral
tags: Java
tags:
- Java
- Difficulty-Beginner
- Gang Of Four
---
**Intent:** Define a family of algorithms, encapsulate each one, and make them
......@@ -19,3 +22,7 @@ that use it.
* you need different variants of an algorithm. for example, you might define algorithms reflecting different space/time trade-offs. Strategies can be used when these variants are implemented as a class hierarchy of algorithms
* an algorithm uses data that clients shouldn't know about. Use the Strategy pattern to avoid exposing complex, algorithm-specific data structures
* a class defines many behaviors, and these appear as multiple conditional statements in its operations. Instead of many conditionals, move related conditional branches into their own Strategy class
**Credits**
* [Design Patterns: Elements of Reusable Object-Oriented Software](http://www.amazon.com/Design-Patterns-Elements-Reusable-Object-Oriented/dp/0201633612)
......@@ -4,7 +4,10 @@ title: Template method
folder: template-method
permalink: /patterns/template-method/
categories: Behavioral
tags: Java
tags:
- Java
- Difficulty-Beginner
- Gang Of Four
---
**Intent:** Define the skeleton of an algorithm in an operation, deferring some
......@@ -18,3 +21,7 @@ an algorithm without changing the algorithm's structure.
* to implement the invariant parts of an algorithm once and leave it up to subclasses to implement the behavior that can vary
* when common behavior among subclasses should be factored and localized in a common class to avoid code duplication. This is good example of "refactoring to generalize" as described by Opdyke and Johnson. You first identify the differences in the existing code and then separate the differences into new operations. Finally, you replace the differing code with a template method that calls one of these new operations
* to control subclasses extensions. You can define a template method that calls "hook" operations at specific points, thereby permitting extensions only at those points
**Credits**
* [Design Patterns: Elements of Reusable Object-Oriented Software](http://www.amazon.com/Design-Patterns-Elements-Reusable-Object-Oriented/dp/0201633612)
......@@ -4,7 +4,10 @@ title: Visitor
folder: visitor
permalink: /patterns/visitor/
categories: Behavioral
tags: Java
tags:
- Java
- Difficulty-Expert
- Gang Of Four
---
**Intent:** Represent an operation to be performed on the elements of an object
......@@ -22,3 +25,7 @@ of the elements on which it operates.
**Real world examples:**
* [Apache Wicket](https://github.com/apache/wicket) component tree, see [MarkupContainer](https://github.com/apache/wicket/blob/b60ec64d0b50a611a9549809c9ab216f0ffa3ae3/wicket-core/src/main/java/org/apache/wicket/MarkupContainer.java)
**Credits**
* [Design Patterns: Elements of Reusable Object-Oriented Software](http://www.amazon.com/Design-Patterns-Elements-Reusable-Object-Oriented/dp/0201633612)
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册