Skip to content

Commit fcd500d

Browse files
committed
Added comments and class diagram.
1 parent cd58115 commit fcd500d

File tree

17 files changed

+292
-1
lines changed

17 files changed

+292
-1
lines changed
48.9 KB
Loading
Lines changed: 212 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,212 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<class-diagram version="1.1.8" icons="true" automaticImage="PNG" always-add-relationships="false" generalizations="true"
3+
realizations="true" associations="true" dependencies="false" nesting-relationships="true">
4+
<class id="1" language="java" name="com.iluwatar.creature.KillerBee" project="specification"
5+
file="/specification/src/main/java/com/iluwatar/creature/KillerBee.java" binary="false" corner="BOTTOM_RIGHT">
6+
<position height="88" width="127" x="535" y="361"/>
7+
<display autosize="true" stereotype="true" package="true" initial-value="false" signature="true"
8+
sort-features="false" accessors="true" visibility="true">
9+
<attributes public="true" package="true" protected="true" private="true" static="true"/>
10+
<operations public="true" package="true" protected="true" private="true" static="true"/>
11+
</display>
12+
</class>
13+
<enumeration id="2" language="java" name="com.iluwatar.property.Size" project="specification"
14+
file="/specification/src/main/java/com/iluwatar/property/Size.java" binary="false" corner="BOTTOM_RIGHT">
15+
<position height="178" width="144" x="351" y="361"/>
16+
<display autosize="true" stereotype="true" package="true" initial-value="false" signature="true"
17+
sort-features="false" accessors="true" visibility="true">
18+
<attributes public="true" package="true" protected="true" private="true" static="true"/>
19+
<operations public="true" package="true" protected="true" private="true" static="true"/>
20+
</display>
21+
</enumeration>
22+
<class id="3" language="java" name="com.iluwatar.creature.Troll" project="specification"
23+
file="/specification/src/main/java/com/iluwatar/creature/Troll.java" binary="false" corner="BOTTOM_RIGHT">
24+
<position height="88" width="127" x="702" y="361"/>
25+
<display autosize="true" stereotype="true" package="true" initial-value="false" signature="true"
26+
sort-features="false" accessors="true" visibility="true">
27+
<attributes public="true" package="true" protected="true" private="true" static="true"/>
28+
<operations public="true" package="true" protected="true" private="true" static="true"/>
29+
</display>
30+
</class>
31+
<class id="4" language="java" name="com.iluwatar.selector.SizeSelector" project="specification"
32+
file="/specification/src/main/java/com/iluwatar/selector/SizeSelector.java" binary="false" corner="BOTTOM_RIGHT">
33+
<position height="106" width="154" x="389" y="126"/>
34+
<display autosize="true" stereotype="true" package="true" initial-value="false" signature="true"
35+
sort-features="false" accessors="true" visibility="true">
36+
<attributes public="true" package="true" protected="true" private="true" static="true"/>
37+
<operations public="true" package="true" protected="true" private="true" static="true"/>
38+
</display>
39+
</class>
40+
<class id="5" language="java" name="com.iluwatar.selector.MovementSelector" project="specification"
41+
file="/specification/src/main/java/com/iluwatar/selector/MovementSelector.java" binary="false" corner="BOTTOM_RIGHT">
42+
<position height="106" width="200" x="149" y="126"/>
43+
<display autosize="true" stereotype="true" package="true" initial-value="false" signature="true"
44+
sort-features="false" accessors="true" visibility="true">
45+
<attributes public="true" package="true" protected="true" private="true" static="true"/>
46+
<operations public="true" package="true" protected="true" private="true" static="true"/>
47+
</display>
48+
</class>
49+
<class id="6" language="java" name="com.iluwatar.creature.Shark" project="specification"
50+
file="/specification/src/main/java/com/iluwatar/creature/Shark.java" binary="false" corner="BOTTOM_RIGHT">
51+
<position height="88" width="127" x="869" y="361"/>
52+
<display autosize="true" stereotype="true" package="true" initial-value="false" signature="true"
53+
sort-features="false" accessors="true" visibility="true">
54+
<attributes public="true" package="true" protected="true" private="true" static="true"/>
55+
<operations public="true" package="true" protected="true" private="true" static="true"/>
56+
</display>
57+
</class>
58+
<class id="7" language="java" name="com.iluwatar.creature.Dragon" project="specification"
59+
file="/specification/src/main/java/com/iluwatar/creature/Dragon.java" binary="false" corner="BOTTOM_RIGHT">
60+
<position height="88" width="127" x="1036" y="361"/>
61+
<display autosize="true" stereotype="true" package="true" initial-value="false" signature="true"
62+
sort-features="false" accessors="true" visibility="true">
63+
<attributes public="true" package="true" protected="true" private="true" static="true"/>
64+
<operations public="true" package="true" protected="true" private="true" static="true"/>
65+
</display>
66+
</class>
67+
<class id="8" language="java" name="com.iluwatar.creature.AbstractCreature" project="specification"
68+
file="/specification/src/main/java/com/iluwatar/creature/AbstractCreature.java" binary="false" corner="BOTTOM_RIGHT">
69+
<position height="-1" width="-1" x="1101" y="222"/>
70+
<display autosize="true" stereotype="true" package="true" initial-value="false" signature="true"
71+
sort-features="false" accessors="true" visibility="true">
72+
<attributes public="true" package="true" protected="true" private="true" static="true"/>
73+
<operations public="true" package="true" protected="true" private="true" static="true"/>
74+
</display>
75+
</class>
76+
<class id="9" language="java" name="com.iluwatar.creature.Octopus" project="specification"
77+
file="/specification/src/main/java/com/iluwatar/creature/Octopus.java" binary="false" corner="BOTTOM_RIGHT">
78+
<position height="88" width="127" x="1203" y="361"/>
79+
<display autosize="true" stereotype="true" package="true" initial-value="false" signature="true"
80+
sort-features="false" accessors="true" visibility="true">
81+
<attributes public="true" package="true" protected="true" private="true" static="true"/>
82+
<operations public="true" package="true" protected="true" private="true" static="true"/>
83+
</display>
84+
</class>
85+
<class id="10" language="java" name="com.iluwatar.selector.ColorSelector" project="specification"
86+
file="/specification/src/main/java/com/iluwatar/selector/ColorSelector.java" binary="false" corner="BOTTOM_RIGHT">
87+
<position height="-1" width="-1" x="1647" y="223"/>
88+
<display autosize="true" stereotype="true" package="true" initial-value="false" signature="true"
89+
sort-features="false" accessors="true" visibility="true">
90+
<attributes public="true" package="true" protected="true" private="true" static="true"/>
91+
<operations public="true" package="true" protected="true" private="true" static="true"/>
92+
</display>
93+
</class>
94+
<interface id="11" language="java" name="com.iluwatar.creature.Creature" project="specification"
95+
file="/specification/src/main/java/com/iluwatar/creature/Creature.java" binary="false" corner="BOTTOM_RIGHT">
96+
<position height="-1" width="-1" x="717" y="223"/>
97+
<display autosize="true" stereotype="true" package="true" initial-value="false" signature="true"
98+
sort-features="false" accessors="true" visibility="true">
99+
<attributes public="true" package="true" protected="true" private="true" static="true"/>
100+
<operations public="true" package="true" protected="true" private="true" static="true"/>
101+
</display>
102+
</interface>
103+
<enumeration id="12" language="java" name="com.iluwatar.property.Movement" project="specification"
104+
file="/specification/src/main/java/com/iluwatar/property/Movement.java" binary="false" corner="BOTTOM_RIGHT">
105+
<position height="178" width="162" x="149" y="361"/>
106+
<display autosize="true" stereotype="true" package="true" initial-value="false" signature="true"
107+
sort-features="false" accessors="true" visibility="true">
108+
<attributes public="true" package="true" protected="true" private="true" static="true"/>
109+
<operations public="true" package="true" protected="true" private="true" static="true"/>
110+
</display>
111+
</enumeration>
112+
<class id="13" language="java" name="com.iluwatar.creature.Goblin" project="specification"
113+
file="/specification/src/main/java/com/iluwatar/creature/Goblin.java" binary="false" corner="BOTTOM_RIGHT">
114+
<position height="-1" width="-1" x="1447" y="405"/>
115+
<display autosize="true" stereotype="true" package="true" initial-value="false" signature="true"
116+
sort-features="false" accessors="true" visibility="true">
117+
<attributes public="true" package="true" protected="true" private="true" static="true"/>
118+
<operations public="true" package="true" protected="true" private="true" static="true"/>
119+
</display>
120+
</class>
121+
<enumeration id="14" language="java" name="com.iluwatar.property.Color" project="specification"
122+
file="/specification/src/main/java/com/iluwatar/property/Color.java" binary="false" corner="BOTTOM_RIGHT">
123+
<position height="-1" width="-1" x="1416" y="223"/>
124+
<display autosize="true" stereotype="true" package="true" initial-value="false" signature="true"
125+
sort-features="false" accessors="true" visibility="true">
126+
<attributes public="true" package="true" protected="true" private="true" static="true"/>
127+
<operations public="true" package="true" protected="true" private="true" static="true"/>
128+
</display>
129+
</enumeration>
130+
<generalization id="15">
131+
<end type="SOURCE" refId="1"/>
132+
<end type="TARGET" refId="8"/>
133+
</generalization>
134+
<generalization id="16">
135+
<end type="SOURCE" refId="6"/>
136+
<end type="TARGET" refId="8"/>
137+
</generalization>
138+
<generalization id="17">
139+
<end type="SOURCE" refId="3"/>
140+
<end type="TARGET" refId="8"/>
141+
</generalization>
142+
<association id="18">
143+
<end type="SOURCE" refId="8" navigable="false">
144+
<attribute id="19" name="size"/>
145+
<multiplicity id="20" minimum="0" maximum="1"/>
146+
</end>
147+
<end type="TARGET" refId="2" navigable="true"/>
148+
<display labels="true" multiplicity="true"/>
149+
</association>
150+
<association id="21">
151+
<end type="SOURCE" refId="8" navigable="false">
152+
<attribute id="22" name="movement"/>
153+
<multiplicity id="23" minimum="0" maximum="1"/>
154+
</end>
155+
<end type="TARGET" refId="12" navigable="true"/>
156+
<display labels="true" multiplicity="true"/>
157+
</association>
158+
<generalization id="24">
159+
<end type="SOURCE" refId="9"/>
160+
<end type="TARGET" refId="8"/>
161+
</generalization>
162+
<association id="25">
163+
<end type="SOURCE" refId="4" navigable="false">
164+
<attribute id="26" name="s"/>
165+
<multiplicity id="27" minimum="0" maximum="1"/>
166+
</end>
167+
<end type="TARGET" refId="2" navigable="true"/>
168+
<display labels="true" multiplicity="true"/>
169+
</association>
170+
<association id="28">
171+
<end type="SOURCE" refId="8" navigable="false">
172+
<attribute id="29" name="color"/>
173+
<multiplicity id="30" minimum="0" maximum="1"/>
174+
</end>
175+
<end type="TARGET" refId="14" navigable="true"/>
176+
<display labels="true" multiplicity="true"/>
177+
</association>
178+
<generalization id="31">
179+
<end type="SOURCE" refId="7"/>
180+
<end type="TARGET" refId="8"/>
181+
</generalization>
182+
<realization id="32">
183+
<end type="SOURCE" refId="8"/>
184+
<end type="TARGET" refId="11"/>
185+
</realization>
186+
<generalization id="33">
187+
<end type="SOURCE" refId="13"/>
188+
<end type="TARGET" refId="8"/>
189+
</generalization>
190+
<association id="34">
191+
<end type="SOURCE" refId="5" navigable="false">
192+
<attribute id="35" name="m"/>
193+
<multiplicity id="36" minimum="0" maximum="1"/>
194+
</end>
195+
<end type="TARGET" refId="12" navigable="true"/>
196+
<display labels="true" multiplicity="true"/>
197+
</association>
198+
<association id="37">
199+
<end type="SOURCE" refId="10" navigable="false">
200+
<attribute id="38" name="c"/>
201+
<multiplicity id="39" minimum="0" maximum="1"/>
202+
</end>
203+
<end type="TARGET" refId="14" navigable="true"/>
204+
<display labels="true" multiplicity="true"/>
205+
</association>
206+
<classifier-display autosize="true" stereotype="true" package="true" initial-value="false" signature="true"
207+
sort-features="false" accessors="true" visibility="true">
208+
<attributes public="true" package="true" protected="true" private="true" static="true"/>
209+
<operations public="true" package="true" protected="true" private="true" static="true"/>
210+
</classifier-display>
211+
<association-display labels="true" multiplicity="true"/>
212+
</class-diagram>

specification/src/main/java/com/iluwatar/app/App.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,21 @@
1616
import com.iluwatar.selector.ColorSelector;
1717
import com.iluwatar.selector.MovementSelector;
1818

19+
/**
20+
*
21+
* The central idea of Specification pattern is to separate the statement of how to match a candidate, from the
22+
* candidate object that it is matched against. As well as its usefulness in selection, it is also valuable for
23+
* validation and for building to order.
24+
*
25+
* In this example we have a pool of creatures with different properties. We then have defined separate selection
26+
* rules (Specifications) that we apply to the collection and as output receive only the creatures that match
27+
* the selection criteria.
28+
*
29+
* http://martinfowler.com/apsupp/spec.pdf
30+
*
31+
*/
1932
public class App {
33+
2034
public static void main( String[] args ) {
2135
// initialize creatures list
2236
List<Creature> creatures = Arrays.asList(new Goblin(), new Octopus(), new Dragon(), new Shark(), new Troll(), new KillerBee());

specification/src/main/java/com/iluwatar/creature/AbstractCreature.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,11 @@
44
import com.iluwatar.property.Movement;
55
import com.iluwatar.property.Size;
66

7+
/**
8+
*
9+
* Base class for concrete creatures.
10+
*
11+
*/
712
public abstract class AbstractCreature implements Creature {
813

914
private String name;

specification/src/main/java/com/iluwatar/creature/Creature.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,11 @@
44
import com.iluwatar.property.Movement;
55
import com.iluwatar.property.Size;
66

7+
/**
8+
*
9+
* Creature interface.
10+
*
11+
*/
712
public interface Creature {
813

914
String getName();

specification/src/main/java/com/iluwatar/creature/Dragon.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,11 @@
44
import com.iluwatar.property.Movement;
55
import com.iluwatar.property.Size;
66

7+
/**
8+
*
9+
* Dragon creature.
10+
*
11+
*/
712
public class Dragon extends AbstractCreature {
813

914
public Dragon() {

specification/src/main/java/com/iluwatar/creature/Goblin.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,11 @@
44
import com.iluwatar.property.Movement;
55
import com.iluwatar.property.Size;
66

7+
/**
8+
*
9+
* Goblin creature.
10+
*
11+
*/
712
public class Goblin extends AbstractCreature {
813

914
public Goblin() {

specification/src/main/java/com/iluwatar/creature/KillerBee.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,11 @@
44
import com.iluwatar.property.Movement;
55
import com.iluwatar.property.Size;
66

7+
/**
8+
*
9+
* KillerBee creature.
10+
*
11+
*/
712
public class KillerBee extends AbstractCreature {
813

914
public KillerBee() {

specification/src/main/java/com/iluwatar/creature/Octopus.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,11 @@
44
import com.iluwatar.property.Movement;
55
import com.iluwatar.property.Size;
66

7+
/**
8+
*
9+
* Octopus creature.
10+
*
11+
*/
712
public class Octopus extends AbstractCreature {
813

914
public Octopus() {

specification/src/main/java/com/iluwatar/creature/Shark.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,11 @@
44
import com.iluwatar.property.Movement;
55
import com.iluwatar.property.Size;
66

7+
/**
8+
*
9+
* Shark creature.
10+
*
11+
*/
712
public class Shark extends AbstractCreature {
813

914
public Shark() {

0 commit comments

Comments
 (0)