Skip to content

Commit 1bef44c

Browse files
MarkusMarkus
Markus
authored and
Markus
committed
- Removed Self-Links and instead used another way of making custom id's - Removed TOC - Removed Back to top arrows - Made FAQ an extra page
1 parent 0989c9b commit 1bef44c

File tree

2 files changed

+70
-80
lines changed

2 files changed

+70
-80
lines changed

README.md

Lines changed: 7 additions & 80 deletions
Original file line numberDiff line numberDiff line change
@@ -4,25 +4,12 @@
44

55
# Design pattern samples in Java
66

7+
[![Build status](https://travis-ci.org/iluwatar/java-design-patterns.svg?branch=master)](https://travis-ci.org/iluwatar/java-design-patterns)
8+
[![Coverage Status](https://coveralls.io/repos/iluwatar/java-design-patterns/badge.svg?branch=master)](https://coveralls.io/r/iluwatar/java-design-patterns?branch=master)
9+
[![Coverity Scan Build Status](https://scan.coverity.com/projects/5634/badge.svg)](https://scan.coverity.com/projects/5634)
710
[![Join the chat at https://gitter.im/iluwatar/java-design-patterns](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/iluwatar/java-design-patterns?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
811

9-
[![Build status](https://travis-ci.org/iluwatar/java-design-patterns.svg?branch=master)](https://travis-ci.org/iluwatar/java-design-patterns) [![Coverage Status](https://coveralls.io/repos/iluwatar/java-design-patterns/badge.svg?branch=master)](https://coveralls.io/r/iluwatar/java-design-patterns?branch=master) <a href="https://scan.coverity.com/projects/5634">
10-
<img alt="Coverity Scan Build Status"
11-
src="https://scan.coverity.com/projects/5634/badge.svg"/>
12-
</a>
13-
14-
15-
<a name="top"/>
16-
17-
# <a name="toc">Table of Contents</a>
18-
- <a href="#introduction">Introduction</a>
19-
- <a href="#contribute">How to contribute</a>
20-
- <a href="#faq">Frequently Asked Questions</a>
21-
- <a href="#credits">Credits</a>
22-
- <a href="#license">License</a>
23-
24-
25-
# <a name="introduction">Introduction</a> [&#8593;](#top)
12+
# Introduction {#intro}
2613

2714
Design patterns are formalized best practices that the programmer can use to
2815
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
3522
are familiar with the patterns.
3623

3724

38-
# <a name="contribute">How to contribute</a> [&#8593;](#top)
25+
# How to contribute {#contribute}
3926

4027
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).
4128

42-
43-
# <a name="faq">Frequently asked questions</a> [&#8593;](#top)
44-
45-
**<a id="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-
**<a id="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-
**<a id="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-
**<a id="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-
**<a id="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-
**<a id="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-
# <a name="credits">Credits</a> [&#8593;](#top)
29+
# Credits {#credits}
10330

10431
* [Design Patterns: Elements of Reusable Object-Oriented Software](http://www.amazon.com/Design-Patterns-Elements-Reusable-Object-Oriented/dp/0201633612)
10532
* [Effective Java (2nd Edition)](http://www.amazon.com/Effective-Java-Edition-Joshua-Bloch/dp/0321356683)
@@ -114,6 +41,6 @@ Flyweight.
11441
* [Pattern Oriented Software Architecture Vol I-V](http://www.amazon.com/Pattern-Oriented-Software-Architecture-Volume-Patterns/dp/0471958697)
11542

11643

117-
# <a name="license">License</a> [&#8593;](#top)
44+
# License {#license}
11845

11946
This project is licensed under the terms of the MIT license.

faq.md

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
---
2+
layout: page
3+
title: FAQ
4+
permalink: /faq/
5+
icon: fa-question
6+
page-index: 2
7+
---
8+
9+
### Q1: What is the difference between State and Strategy patterns? {#Q1}
10+
11+
While the implementation is similar they solve different problems. The State
12+
pattern deals with what state an object is in - it encapsulates state-dependent
13+
behavior.
14+
The Strategy pattern deals with how an object performs a certain task - it
15+
encapsulates an algorithm.
16+
17+
### Q2: What is the difference between Strategy and Template Method patterns? {#Q2}
18+
19+
In Template Method the algorithm is chosen at compile time via inheritance.
20+
With Strategy pattern the algorithm is chosen at runtime via composition.
21+
22+
### Q3: What is the difference between Proxy and Decorator patterns? {#Q3}
23+
24+
The difference is the intent of the patterns. While Proxy controls access to
25+
the object Decorator is used to add responsibilities to the object.
26+
27+
### Q4: What is the difference between Chain of Responsibility and Intercepting Filter patterns? {#Q4}
28+
29+
While the implementations look similar there are differences. The Chain of
30+
Responsibility forms a chain of request processors and the processors are then
31+
executed one by one until the correct processor is found. In Intercepting
32+
Filter the chain is constructed from filters and the whole chain is always
33+
executed.
34+
35+
### Q5: What is the difference between Visitor and Double Dispatch patterns? {#Q5}
36+
37+
The Visitor pattern is a means of adding a new operation to existing classes.
38+
Double dispatch is a means of dispatching function calls with respect to two
39+
polymorphic types, rather than a single polymorphic type, which is what
40+
languages like C++ and Java _do not_ support directly.
41+
42+
### Q6: What are the differences between Flyweight and Object Pool patterns? {#Q6}
43+
44+
They differ in the way they are used.
45+
46+
Pooled objects can simultaneously be used by a single "client" only. For that,
47+
a pooled object must be checked out from the pool, then it can be used by a
48+
client, and then the client must return the object back to the pool. Multiple
49+
instances of identical objects may exist, up to the maximal capacity of the
50+
pool.
51+
52+
In contrast, a Flyweight object is singleton, and it can be used simultaneously
53+
by multiple clients.
54+
55+
As for concurrent access, pooled objects can be mutable and they usually don't
56+
need to be thread safe, as typically, only one thread is going to use a
57+
specific instance at the same time. Flyweight must either be immutable (the
58+
best option), or implement thread safety.
59+
60+
As for performance and scalability, pools can become bottlenecks, if all the
61+
pooled objects are in use and more clients need them, threads will become
62+
blocked waiting for available object from the pool. This is not the case with
63+
Flyweight.

0 commit comments

Comments
 (0)