Skip to content

Commit 7bb84a2

Browse files
committed
add some use case
1 parent 97431a6 commit 7bb84a2

File tree

3 files changed

+28
-0
lines changed

3 files changed

+28
-0
lines changed

README.md

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,11 @@
5555
* the must be exactly one instance of a class, and it must be accessible to clients from a well-known access point
5656
* when the sole instance should be extensible by subclassing, and clients should be able to use an extended instance without modifying their code
5757

58+
**Typical Use Case:**
59+
* the logging class
60+
* managing a connection to a database
61+
* file manager
62+
5863
##Adapter
5964
**Intent:** Convert the interface of a class into another interface the clients expect. Adapter lets classes work together that couldn't otherwise because of incompatible interfaces.
6065

@@ -125,10 +130,20 @@
125130
![alt text](https://github.com/llitfkitfk/java-design-patterns/blob/master/proxy/etc/proxy_1.png "Proxy")
126131

127132
**Applicability:** Proxy is applicable whenever there is a need for a more versatile or sophisticated reference to an object than a simple pointer. here are several common situations in which the Proxy pattern is applicable
133+
128134
* a remote proxy provides a local representative for an object in a different address space.
129135
* a virtual proxy creates expensive objects on demand.
130136
* a protection proxy controls access to the original object. Protection proxies are useful when objects should have different access rights.
131137

138+
**Typical Use Case:**
139+
140+
* Control access to another object
141+
* Lazy initialization
142+
* implement logging
143+
* facilitate network connection
144+
* to count references to an object
145+
146+
132147
##Chain of responsibility
133148
**Intent:** Avoid coupling the sender of a request to its receiver by giving more than one object a chance to handle the request. Chain the receiving objects and pass the request along the chain until an object handles it.
134149

@@ -145,12 +160,19 @@
145160
![alt text](https://github.com/llitfkitfk/java-design-patterns/blob/master/command/etc/command_1.png "Command")
146161

147162
**Applicability:** Use the Command pattern when you want to
163+
148164
* parameterize objects by an action to perform. You can express such parameterization in a procedural language with a callback function, that is, a function that's registered somewhere to be called at a later point. Commands are an object-oriented replacement for callbacks.
149165
* specify, queue, and execute requests at different times. A Command object can have a lifetime independent of the original request. If the receiver of a request can be represented in an address space-independent way, then you can transfer a command object for the request to a different process and fulfill the request there
150166
* support undo. The Command's execute operation can store state for reversing its effects in the command itself. The Command interface must have an added Unexecute operation that reverses the effects of a previous call to execute. Executed commands are stored in a history list. Unlimited-level undo and redo is achieved by traversing this list backwards and forwards calling unexecute and execute, respectively
151167
* support logging changes so that they can be reapplied in case of a system crash. By augmenting the Command interface with load and store operations, you can keep a persistent log of changes. Recovering from a crash involves reloading logged commands from disk and re-executing them with the execute operation
152168
* structure a system around high-level operations build on primitive operations. Such a structure is common in information systems that support transactions. A transaction encapsulates a set of changes to data. The Command pattern offers a way to model transactions. Commands have a common interface, letting you invoke all transactions the same way. The pattern also makes it easy to extend the system with new transactions
153169

170+
**Typical Use Case:**
171+
172+
* to keep a history of requests
173+
* implement callback functionality
174+
* implement the undo functionality
175+
154176
##Interpreter
155177
**Intent:** Given a language, define a representation for its grammar along with an interpreter that uses the representation to interpret sentences in the language.
156178

@@ -204,10 +226,16 @@
204226
![alt text](https://github.com/llitfkitfk/java-design-patterns/blob/master/observer/etc/observer_1.png "Observer")
205227

206228
**Applicability:** Use the Observer pattern in any of the following situations
229+
207230
* when an abstraction has two aspects, one dependent on the other. Encapsulating these aspects in separate objects lets you vary and reuse them independently
208231
* when a change to one object requires changing others, and you don't know how many objects need to be changed
209232
* when an object should be able to notify other objects without making assumptions about who these objects are. In other words, you don't want these objects tightly coupled
210233

234+
**Typical Use Case:**
235+
236+
* changing in one object leads to a change in other objects
237+
238+
211239
##State
212240
**Intent:** Allow an object to alter its behavior when its internal state changes. The object will appear to change its class.
213241

design_pattern_relationship.gif

42.2 KB
Loading

design_pattern_relationship_1.gif

56.8 KB
Loading

0 commit comments

Comments
 (0)