You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
[](https://gitter.im/iluwatar/java-design-patterns?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
Design patterns are formalized best practices that the programmer can use to
28
15
solve common problems when designing an application or system.
@@ -35,71 +22,11 @@ problems, and it also improves code readability for coders and architects who
35
22
are familiar with the patterns.
36
23
37
24
38
-
# <aname="contribute">How to contribute</a> [↑](#top)
25
+
# How to contribute {#contribute}
39
26
40
27
If you are willing to contribute to the project you will find the relevant information in our [developer wiki](https://github.com/iluwatar/java-design-patterns/wiki).
**<aid="Q1">Q: What is the difference between State and Strategy patterns?</a>**
46
-
47
-
While the implementation is similar they solve different problems. The State
48
-
pattern deals with what state an object is in - it encapsulates state-dependent
49
-
behavior.
50
-
The Strategy pattern deals with how an object performs a certain task - it
51
-
encapsulates an algorithm.
52
-
53
-
**<aid="Q2">Q: What is the difference between Strategy and Template Method patterns?</a>**
54
-
55
-
In Template Method the algorithm is chosen at compile time via inheritance.
56
-
With Strategy pattern the algorithm is chosen at runtime via composition.
57
-
58
-
**<aid="Q3">Q: What is the difference between Proxy and Decorator patterns?</a>**
59
-
60
-
The difference is the intent of the patterns. While Proxy controls access to
61
-
the object Decorator is used to add responsibilities to the object.
62
-
63
-
**<aid="Q4">Q: What is the difference between Chain of Responsibility and Intercepting Filter patterns?</a>**
64
-
65
-
While the implementations look similar there are differences. The Chain of
66
-
Responsibility forms a chain of request processors and the processors are then
67
-
executed one by one until the correct processor is found. In Intercepting
68
-
Filter the chain is constructed from filters and the whole chain is always
69
-
executed.
70
-
71
-
**<aid="Q5">Q: What is the difference between Visitor and Double Dispatch patterns?</a>**
72
-
73
-
The Visitor pattern is a means of adding a new operation to existing classes.
74
-
Double dispatch is a means of dispatching function calls with respect to two
75
-
polymorphic types, rather than a single polymorphic type, which is what
76
-
languages like C++ and Java _do not_ support directly.
77
-
78
-
**<aid="Q6">Q: What are the differences between Flyweight and Object Pool patterns?</a>**
79
-
80
-
They differ in the way they are used.
81
-
82
-
Pooled objects can simultaneously be used by a single "client" only. For that,
83
-
a pooled object must be checked out from the pool, then it can be used by a
84
-
client, and then the client must return the object back to the pool. Multiple
85
-
instances of identical objects may exist, up to the maximal capacity of the
86
-
pool.
87
-
88
-
In contrast, a Flyweight object is singleton, and it can be used simultaneously
89
-
by multiple clients.
90
-
91
-
As for concurrent access, pooled objects can be mutable and they usually don't
92
-
need to be thread safe, as typically, only one thread is going to use a
93
-
specific instance at the same time. Flyweight must either be immutable (the
94
-
best option), or implement thread safety.
95
-
96
-
As for performance and scalability, pools can become bottlenecks, if all the
97
-
pooled objects are in use and more clients need them, threads will become
98
-
blocked waiting for available object from the pool. This is not the case with
99
-
Flyweight.
100
-
101
-
102
-
# <aname="credits">Credits</a> [↑](#top)
29
+
# Credits {#credits}
103
30
104
31
*[Design Patterns: Elements of Reusable Object-Oriented Software](http://www.amazon.com/Design-Patterns-Elements-Reusable-Object-Oriented/dp/0201633612)
0 commit comments