Skip to content

Commit aebd69e

Browse files
committed
Work on iluwatar#74, Merged from master
2 parents 9e401b0 + 611a82a commit aebd69e

File tree

18 files changed

+1206
-85
lines changed

18 files changed

+1206
-85
lines changed

.travis.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,18 @@ language: java
33
jdk:
44
- oraclejdk8
55

6+
env:
7+
global:
8+
- GH_REF: github.com/iluwatar/java-design-patterns.git
9+
- secure: "LxTDuNS/rBWIvKkaEqr79ImZAe48mCdoYCF41coxNXgNoippo4GIBArknqtv+XvdkiuRZ1yGyj6pn8GU33c/yn+krddTUkVCwTbVatbalW5jhQjDbHYym/JcxaK9ZS/3JTeGcWrBgiPqHEEDhCf26vPZsXoMSeVCEORVKTp1BSg="
10+
611
before_install:
712
- "export DISPLAY=:99.0"
813
- "sh -e /etc/init.d/xvfb start"
914

1015
after_success:
1116
- mvn clean test jacoco:report coveralls:report
17+
- bash update-ghpages.sh
1218

1319
# Migration to container-based infrastructure
1420
sudo: false

README.md

Lines changed: 15 additions & 79 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
2613

2714
Design patterns are formalized best practices that the programmer can use to
2815
solve common problems when designing an application or system.
@@ -34,72 +21,22 @@ Reusing design patterns helps to prevent subtle issues that can cause major
3421
problems, and it also improves code readability for coders and architects who
3522
are familiar with the patterns.
3623

24+
# Getting started
3725

38-
# <a name="contribute">How to contribute</a> [&#8593;](#top)
39-
40-
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).
41-
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>**
26+
Before you dive into the material, you should be familiar with various
27+
[Programming/Software Design Principles](http://webpro.github.io/programming-principles/).
5428

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.
29+
Once you are familiar with these concepts you can start drilling down into patterns by any of the following approaches
5730

58-
**<a id="Q3">Q: What is the difference between Proxy and Decorator patterns?</a>**
31+
- Using difficulty tags, `Difficulty-Beginner`, `Difficulty-Intermediate` & `Difficulty-Expert`.
32+
- Using pattern categories, `Creational`, `Behavioral` and others.
33+
- Search for a specific pattern. Can't find one? Please report a new pattern [here](https://github.com/iluwatar/java-design-patterns/issues).
5934

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.
35+
# How to contribute
10036

37+
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).
10138

102-
# <a name="credits">Credits</a> [&#8593;](#top)
39+
# Credits
10340

10441
* [Design Patterns: Elements of Reusable Object-Oriented Software](http://www.amazon.com/Design-Patterns-Elements-Reusable-Object-Oriented/dp/0201633612)
10542
* [Effective Java (2nd Edition)](http://www.amazon.com/Effective-Java-Edition-Joshua-Bloch/dp/0321356683)
@@ -113,7 +50,6 @@ Flyweight.
11350
* [J2EE Design Patterns](http://www.amazon.com/J2EE-Design-Patterns-William-Crawford/dp/0596004273/ref=sr_1_2)
11451
* [Pattern Oriented Software Architecture Vol I-V](http://www.amazon.com/Pattern-Oriented-Software-Architecture-Volume-Patterns/dp/0471958697)
11552

116-
117-
# <a name="license">License</a> [&#8593;](#top)
53+
# License
11854

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

checkstyle.xml

Lines changed: 208 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,208 @@
1+
<?xml version="1.0"?>
2+
<!DOCTYPE module PUBLIC
3+
"-//Puppy Crawl//DTD Check Configuration 1.3//EN"
4+
"http://www.puppycrawl.com/dtds/configuration_1_3.dtd">
5+
6+
<!--
7+
8+
Source = https://github.com/checkstyle/checkstyle/tree/master/src/main/resources
9+
10+
Checkstyle configurartion that checks the Google coding conventions from:
11+
12+
- Google Java Style
13+
https://google-styleguide.googlecode.com/svn-history/r130/trunk/javaguide.html
14+
15+
Checkstyle is very configurable. Be sure to read the documentation at
16+
http://checkstyle.sf.net (or in your downloaded distribution).
17+
18+
Most Checks are configurable, be sure to consult the documentation.
19+
20+
To completely disable a check, just comment it out or delete it from the file.
21+
22+
Authors: Max Vetrenko, Ruslan Diachenko, Roman Ivanov.
23+
24+
-->
25+
26+
<module name="Checker">
27+
<property name="charset" value="UTF-8"/>
28+
29+
<property name="severity" value="warning"/>
30+
31+
<!-- Checks for whitespace -->
32+
<!-- See http://checkstyle.sf.net/config_whitespace.html -->
33+
<module name="FileTabCharacter">
34+
<property name="eachLine" value="true"/>
35+
</module>
36+
37+
<module name="TreeWalker">
38+
<module name="OuterTypeFilename"/>
39+
<module name="IllegalTokenText">
40+
<property name="tokens" value="STRING_LITERAL, CHAR_LITERAL"/>
41+
<property name="format"
42+
value="\\u00(08|09|0(a|A)|0(c|C)|0(d|D)|22|27|5(C|c))|\\(0(10|11|12|14|15|42|47)|134)"/>
43+
<property name="message" value="Avoid using corresponding octal or Unicode escape."/>
44+
</module>
45+
<module name="AvoidEscapedUnicodeCharacters">
46+
<property name="allowEscapesForControlCharacters" value="true"/>
47+
<property name="allowByTailComment" value="true"/>
48+
<property name="allowNonPrintableEscapes" value="true"/>
49+
</module>
50+
<module name="LineLength">
51+
<property name="max" value="100"/>
52+
<property name="ignorePattern" value="^package.*|^import.*|a href|href|http://|https://|ftp://"/>
53+
</module>
54+
<module name="AvoidStarImport"/>
55+
<module name="OneTopLevelClass"/>
56+
<module name="NoLineWrap"/>
57+
<module name="EmptyBlock">
58+
<property name="option" value="TEXT"/>
59+
<property name="tokens"
60+
value="LITERAL_TRY, LITERAL_CATCH, LITERAL_FINALLY, LITERAL_IF, LITERAL_ELSE, LITERAL_SWITCH"/>
61+
</module>
62+
<module name="NeedBraces"/>
63+
<module name="LeftCurly">
64+
<property name="maxLineLength" value="100"/>
65+
</module>
66+
<module name="RightCurly"/>
67+
<module name="RightCurly">
68+
<property name="option" value="alone"/>
69+
<property name="tokens"
70+
value="CLASS_DEF, METHOD_DEF, CTOR_DEF, LITERAL_FOR, LITERAL_WHILE, LITERAL_DO, STATIC_INIT, INSTANCE_INIT"/>
71+
</module>
72+
<module name="WhitespaceAround">
73+
<property name="allowEmptyConstructors" value="true"/>
74+
<property name="allowEmptyMethods" value="true"/>
75+
<property name="allowEmptyTypes" value="true"/>
76+
<property name="allowEmptyLoops" value="true"/>
77+
<message key="ws.notFollowed"
78+
value="WhitespaceAround: ''{0}'' is not followed by whitespace."/>
79+
<message key="ws.notPreceded"
80+
value="WhitespaceAround: ''{0}'' is not preceded with whitespace."/>
81+
</module>
82+
<module name="OneStatementPerLine"/>
83+
<module name="MultipleVariableDeclarations"/>
84+
<module name="ArrayTypeStyle"/>
85+
<module name="MissingSwitchDefault"/>
86+
<module name="FallThrough"/>
87+
<module name="UpperEll"/>
88+
<module name="ModifierOrder"/>
89+
<module name="EmptyLineSeparator">
90+
<property name="allowNoEmptyLineBetweenFields" value="true"/>
91+
</module>
92+
<module name="SeparatorWrap">
93+
<property name="tokens" value="DOT"/>
94+
<property name="option" value="nl"/>
95+
</module>
96+
<module name="SeparatorWrap">
97+
<property name="tokens" value="COMMA"/>
98+
<property name="option" value="EOL"/>
99+
</module>
100+
<module name="PackageName">
101+
<property name="format" value="^[a-z]+(\.[a-z][a-z0-9]*)*$"/>
102+
<message key="name.invalidPattern"
103+
value="Package name ''{0}'' must match pattern ''{1}''."/>
104+
</module>
105+
<module name="TypeName">
106+
<message key="name.invalidPattern"
107+
value="Type name ''{0}'' must match pattern ''{1}''."/>
108+
</module>
109+
<module name="MemberName">
110+
<property name="format" value="^[a-z][a-z0-9][a-zA-Z0-9]*$"/>
111+
<message key="name.invalidPattern"
112+
value="Member name ''{0}'' must match pattern ''{1}''."/>
113+
</module>
114+
<module name="ParameterName">
115+
<property name="format" value="^[a-z][a-z0-9][a-zA-Z0-9]*$"/>
116+
<message key="name.invalidPattern"
117+
value="Parameter name ''{0}'' must match pattern ''{1}''."/>
118+
</module>
119+
<module name="LocalVariableName">
120+
<property name="tokens" value="VARIABLE_DEF"/>
121+
<property name="format" value="^[a-z][a-z0-9][a-zA-Z0-9]*$"/>
122+
<property name="allowOneCharVarInForLoop" value="true"/>
123+
<message key="name.invalidPattern"
124+
value="Local variable name ''{0}'' must match pattern ''{1}''."/>
125+
</module>
126+
<module name="ClassTypeParameterName">
127+
<property name="format" value="(^[A-Z][0-9]?)$|([A-Z][a-zA-Z0-9]*[T]$)"/>
128+
<message key="name.invalidPattern"
129+
value="Class type name ''{0}'' must match pattern ''{1}''."/>
130+
</module>
131+
<module name="MethodTypeParameterName">
132+
<property name="format" value="(^[A-Z][0-9]?)$|([A-Z][a-zA-Z0-9]*[T]$)"/>
133+
<message key="name.invalidPattern"
134+
value="Method type name ''{0}'' must match pattern ''{1}''."/>
135+
</module>
136+
<module name="NoFinalizer"/>
137+
<module name="GenericWhitespace">
138+
<message key="ws.followed"
139+
value="GenericWhitespace ''{0}'' is followed by whitespace."/>
140+
<message key="ws.preceded"
141+
value="GenericWhitespace ''{0}'' is preceded with whitespace."/>
142+
<message key="ws.illegalFollow"
143+
value="GenericWhitespace ''{0}'' should followed by whitespace."/>
144+
<message key="ws.notPreceded"
145+
value="GenericWhitespace ''{0}'' is not preceded with whitespace."/>
146+
</module>
147+
<module name="Indentation">
148+
<property name="basicOffset" value="2"/>
149+
<property name="braceAdjustment" value="0"/>
150+
<property name="caseIndent" value="2"/>
151+
<property name="throwsIndent" value="4"/>
152+
<property name="lineWrappingIndentation" value="4"/>
153+
<property name="arrayInitIndent" value="2"/>
154+
</module>
155+
<module name="AbbreviationAsWordInName">
156+
<property name="ignoreFinal" value="false"/>
157+
<property name="allowedAbbreviationLength" value="1"/>
158+
</module>
159+
<module name="OverloadMethodsDeclarationOrder"/>
160+
<module name="VariableDeclarationUsageDistance"/>
161+
<module name="CustomImportOrder">
162+
<property name="thirdPartyPackageRegExp" value=".*"/>
163+
<property name="specialImportsRegExp" value="com.google"/>
164+
<property name="sortImportsInGroupAlphabetically" value="true"/>
165+
<property name="customImportOrderRules"
166+
value="STATIC###SPECIAL_IMPORTS###THIRD_PARTY_PACKAGE###STANDARD_JAVA_PACKAGE"/>
167+
</module>
168+
<module name="MethodParamPad"/>
169+
<module name="OperatorWrap">
170+
<property name="option" value="NL"/>
171+
<property name="tokens"
172+
value="BAND, BOR, BSR, BXOR, DIV, EQUAL, GE, GT, LAND, LE, LITERAL_INSTANCEOF, LOR, LT, MINUS, MOD, NOT_EQUAL, PLUS, QUESTION, SL, SR, STAR "/>
173+
</module>
174+
<module name="AnnotationLocation">
175+
<property name="tokens" value="CLASS_DEF, INTERFACE_DEF, ENUM_DEF, METHOD_DEF, CTOR_DEF"/>
176+
</module>
177+
<module name="AnnotationLocation">
178+
<property name="tokens" value="VARIABLE_DEF"/>
179+
<property name="allowSamelineMultipleAnnotations" value="true"/>
180+
</module>
181+
<module name="NonEmptyAtclauseDescription"/>
182+
<module name="JavadocTagContinuationIndentation"/>
183+
<module name="SummaryJavadocCheck">
184+
<property name="forbiddenSummaryFragments"
185+
value="^@return the *|^This method returns |^A [{]@code [a-zA-Z0-9]+[}]( is a )"/>
186+
</module>
187+
<module name="JavadocParagraph"/>
188+
<module name="AtclauseOrder">
189+
<property name="tagOrder" value="@param, @return, @throws, @deprecated"/>
190+
<property name="target" value="CLASS_DEF, INTERFACE_DEF, ENUM_DEF, METHOD_DEF, CTOR_DEF, VARIABLE_DEF"/>
191+
</module>
192+
<module name="JavadocMethod">
193+
<property name="scope" value="public"/>
194+
<property name="allowMissingParamTags" value="true"/>
195+
<property name="allowMissingThrowsTags" value="true"/>
196+
<property name="allowMissingReturnTag" value="true"/>
197+
<property name="minLineCount" value="2"/>
198+
<property name="allowedAnnotations" value="Override, Test"/>
199+
<property name="allowThrowsTagsForSubclasses" value="true"/>
200+
</module>
201+
<module name="MethodName">
202+
<property name="format" value="^[a-z][a-z0-9][a-zA-Z0-9_]*$"/>
203+
<message key="name.invalidPattern"
204+
value="Method name ''{0}'' must match pattern ''{1}''."/>
205+
</module>
206+
<module name="SingleLineJavadoc"/>
207+
</module>
208+
</module>

factory-method/index.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@ title: Factory Method
44
folder: factory-method
55
permalink: /patterns/factory-method/
66
categories: Creational
7-
tags: Java
7+
tags:
8+
- Java
9+
- Difficulty-Beginner
810
---
911

1012
**Intent:** Define an interface for creating an object, but let subclasses

0 commit comments

Comments
 (0)