Compare commits
55 Commits
Author | SHA1 | Date | |
---|---|---|---|
3407392664 | |||
474c218f85 | |||
17ea0b17f6 | |||
7d4ccc6490 | |||
8b06ea52ab | |||
86ee59c232 | |||
6879990857 | |||
855cf75dd6 | |||
ecad864703 | |||
69be74c016 | |||
c723289bbb | |||
477da92e2f | |||
ac57d67f45 | |||
960d2ea6f7 | |||
87cb33f69b | |||
915a1f3eb0 | |||
c8fd0bc23d | |||
696ed86aff | |||
e0b8f6f850 | |||
e01d640499 | |||
7fef5e4cd5 | |||
991ba320a6 | |||
d78434fed8 | |||
f9f93695fe | |||
a367832d9e | |||
36f5947cd7 | |||
f62ae456b0 | |||
5cbf651a3e | |||
e7b119c95c | |||
ec28b1250d | |||
2dcf63c646 | |||
0805716515 | |||
9f797b3009 | |||
33a3d6fef4 | |||
dddfb52c70 | |||
9667878b5f | |||
4c4cbd41cf | |||
f7825f6c99 | |||
8960ef6111 | |||
a82000650d | |||
e9021329e1 | |||
e9a541259b | |||
94fdefee3a | |||
b61b64073a | |||
09c0891948 | |||
90570f809b | |||
55be744c4a | |||
c34975bdff | |||
ed37d5cdc7 | |||
f87754917c | |||
e046007db7 | |||
0306161380 | |||
dea2316f1f | |||
684cad9beb | |||
3c6f7aa046 |
@ -17,7 +17,7 @@ install:
|
|||||||
- mvn install -DskipTests=true -Dmaven.javadoc.skip=true -B -V -e
|
- mvn install -DskipTests=true -Dmaven.javadoc.skip=true -B -V -e
|
||||||
|
|
||||||
after_success:
|
after_success:
|
||||||
- mvn clean org.jacoco:jacoco-maven-plugin:prepare-agent package sonar:sonar -Dsonar.host.url=https://sonarqube.com -Dsonar.login=$SONAR_TOKEN
|
- mvn clean org.jacoco:jacoco-maven-plugin:prepare-agent package sonar:sonar -Dsonar.host.url=https://sonarcloud.io -Dsonar.login=$SONAR_TOKEN
|
||||||
- bash update-ghpages.sh
|
- bash update-ghpages.sh
|
||||||
|
|
||||||
# use latest java version available instead of travis default
|
# use latest java version available instead of travis default
|
||||||
@ -36,4 +36,4 @@ notifications:
|
|||||||
on_failure: always # options: [always|never|change] default: always
|
on_failure: always # options: [always|never|change] default: always
|
||||||
on_start: never # options: [always|never|change] default: always
|
on_start: never # options: [always|never|change] default: always
|
||||||
|
|
||||||
sudo: required
|
sudo: required
|
||||||
|
@ -7,7 +7,7 @@
|
|||||||
[](https://travis-ci.org/iluwatar/java-design-patterns)
|
[](https://travis-ci.org/iluwatar/java-design-patterns)
|
||||||
[](https://raw.githubusercontent.com/iluwatar/java-design-patterns/master/LICENSE.md)
|
[](https://raw.githubusercontent.com/iluwatar/java-design-patterns/master/LICENSE.md)
|
||||||
[](https://gitter.im/iluwatar/java-design-patterns?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
|
[](https://gitter.im/iluwatar/java-design-patterns?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
|
||||||
[](https://sonarqube.com/dashboard/index/com.iluwatar%3Ajava-design-patterns)
|
[](https://sonarcloud.io/dashboard/index/com.iluwatar%3Ajava-design-patterns)
|
||||||
[](https://bestpractices.coreinfrastructure.org/projects/1503)
|
[](https://bestpractices.coreinfrastructure.org/projects/1503)
|
||||||
|
|
||||||
# Introduction
|
# Introduction
|
||||||
|
@ -12,8 +12,6 @@ tags:
|
|||||||
## Intent
|
## Intent
|
||||||
Achieve flexibility of untyped languages and keep the type-safety
|
Achieve flexibility of untyped languages and keep the type-safety
|
||||||
|
|
||||||

|
|
||||||
|
|
||||||

|

|
||||||
|
|
||||||
|
|
||||||
|
Binary file not shown.
Before Width: | Height: | Size: 15 KiB |
@ -1,58 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<class-diagram version="1.1.9" icons="true" automaticImage="PNG" always-add-relationships="false" generalizations="true"
|
|
||||||
realizations="true" associations="true" dependencies="false" nesting-relationships="true" router="FAN">
|
|
||||||
<interface id="1" language="java" name="com.iluwatar.abstractdocument.Document" project="design-patterns"
|
|
||||||
file="/design-patterns/src/com/iluwatar/abstractdocument/Document.java" binary="false" corner="BOTTOM_RIGHT">
|
|
||||||
<position height="-1" width="-1" x="249" y="405"/>
|
|
||||||
<display autosize="true" stereotype="true" package="true" initial-value="false" signature="true"
|
|
||||||
sort-features="false" accessors="true" visibility="true">
|
|
||||||
<attributes public="true" package="true" protected="true" private="true" static="true"/>
|
|
||||||
<operations public="true" package="true" protected="true" private="true" static="true"/>
|
|
||||||
</display>
|
|
||||||
</interface>
|
|
||||||
<class id="2" language="java" name="com.iluwatar.abstractdocument.AbstractDocument" project="design-patterns"
|
|
||||||
file="/design-patterns/src/com/iluwatar/abstractdocument/AbstractDocument.java" binary="false" corner="BOTTOM_RIGHT">
|
|
||||||
<position height="-1" width="-1" x="250" y="237"/>
|
|
||||||
<display autosize="true" stereotype="true" package="true" initial-value="false" signature="true"
|
|
||||||
sort-features="false" accessors="true" visibility="true">
|
|
||||||
<attributes public="true" package="true" protected="true" private="true" static="true"/>
|
|
||||||
<operations public="true" package="true" protected="true" private="true" static="true"/>
|
|
||||||
</display>
|
|
||||||
</class>
|
|
||||||
<class id="3" language="java" name="com.iluwatar.abstractdocument.domain.Car" project="design-patterns"
|
|
||||||
file="/design-patterns/src/com/iluwatar/abstractdocument/domain/Car.java" binary="false" corner="BOTTOM_RIGHT">
|
|
||||||
<position height="-1" width="-1" x="108" y="75"/>
|
|
||||||
<display autosize="true" stereotype="true" package="true" initial-value="false" signature="true"
|
|
||||||
sort-features="false" accessors="true" visibility="true">
|
|
||||||
<attributes public="true" package="true" protected="true" private="true" static="true"/>
|
|
||||||
<operations public="true" package="true" protected="true" private="true" static="true"/>
|
|
||||||
</display>
|
|
||||||
</class>
|
|
||||||
<class id="4" language="java" name="com.iluwatar.abstractdocument.domain.Part" project="design-patterns"
|
|
||||||
file="/design-patterns/src/com/iluwatar/abstractdocument/domain/Part.java" binary="false" corner="BOTTOM_RIGHT">
|
|
||||||
<position height="-1" width="-1" x="400" y="76"/>
|
|
||||||
<display autosize="true" stereotype="true" package="true" initial-value="false" signature="true"
|
|
||||||
sort-features="false" accessors="true" visibility="true">
|
|
||||||
<attributes public="true" package="true" protected="true" private="true" static="true"/>
|
|
||||||
<operations public="true" package="true" protected="true" private="true" static="true"/>
|
|
||||||
</display>
|
|
||||||
</class>
|
|
||||||
<generalization id="5">
|
|
||||||
<end type="SOURCE" refId="4"/>
|
|
||||||
<end type="TARGET" refId="2"/>
|
|
||||||
</generalization>
|
|
||||||
<realization id="6">
|
|
||||||
<end type="SOURCE" refId="2"/>
|
|
||||||
<end type="TARGET" refId="1"/>
|
|
||||||
</realization>
|
|
||||||
<generalization id="7">
|
|
||||||
<end type="SOURCE" refId="3"/>
|
|
||||||
<end type="TARGET" refId="2"/>
|
|
||||||
</generalization>
|
|
||||||
<classifier-display autosize="true" stereotype="true" package="true" initial-value="false" signature="true"
|
|
||||||
sort-features="false" accessors="true" visibility="true">
|
|
||||||
<attributes public="true" package="true" protected="true" private="true" static="true"/>
|
|
||||||
<operations public="true" package="true" protected="true" private="true" static="true"/>
|
|
||||||
</classifier-display>
|
|
||||||
<association-display labels="true" multiplicity="true"/>
|
|
||||||
</class-diagram>
|
|
Binary file not shown.
Before Width: | Height: | Size: 16 KiB After Width: | Height: | Size: 94 KiB |
@ -1,91 +1,137 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<class-diagram version="1.1.9" icons="true" automaticImage="PNG" always-add-relationships="false" generalizations="true"
|
<class-diagram version="1.2.2" icons="true" always-add-relationships="false" generalizations="true" realizations="true"
|
||||||
realizations="true" associations="true" dependencies="false" nesting-relationships="true" router="FAN">
|
associations="true" dependencies="false" nesting-relationships="true" router="FAN">
|
||||||
<interface id="1" language="java" name="com.iluwatar.abstractdocument.Document" project="design-patterns"
|
<class id="1" language="java" name="com.iluwatar.abstractdocument.AbstractDocument" project="abstract-document"
|
||||||
file="/design-patterns/src/com/iluwatar/abstractdocument/Document.java" binary="false" corner="BOTTOM_RIGHT">
|
file="/abstract-document/src/main/java/com/iluwatar/abstractdocument/AbstractDocument.java" binary="false"
|
||||||
<position height="-1" width="-1" x="341" y="376"/>
|
corner="BOTTOM_RIGHT">
|
||||||
<display autosize="true" stereotype="true" package="true" initial-value="false" signature="true"
|
<position height="-1" width="-1" x="659" y="286"/>
|
||||||
sort-features="false" accessors="true" visibility="true">
|
|
||||||
<attributes public="true" package="true" protected="true" private="true" static="true"/>
|
|
||||||
<operations public="true" package="true" protected="true" private="true" static="true"/>
|
|
||||||
</display>
|
|
||||||
</interface>
|
|
||||||
<interface id="2" language="java" name="com.iluwatar.abstractdocument.domain.HasModel" project="design-patterns"
|
|
||||||
file="/design-patterns/src/com/iluwatar/abstractdocument/domain/HasModel.java" binary="false" corner="BOTTOM_RIGHT">
|
|
||||||
<position height="81" width="173" x="41" y="194"/>
|
|
||||||
<display autosize="true" stereotype="true" package="true" initial-value="false" signature="true"
|
|
||||||
sort-features="false" accessors="true" visibility="true">
|
|
||||||
<attributes public="true" package="true" protected="true" private="true" static="true"/>
|
|
||||||
<operations public="true" package="true" protected="true" private="true" static="true"/>
|
|
||||||
</display>
|
|
||||||
</interface>
|
|
||||||
<interface id="3" language="java" name="com.iluwatar.abstractdocument.domain.HasPrice" project="design-patterns"
|
|
||||||
file="/design-patterns/src/com/iluwatar/abstractdocument/domain/HasPrice.java" binary="false" corner="BOTTOM_RIGHT">
|
|
||||||
<position height="81" width="175" x="254" y="194"/>
|
|
||||||
<display autosize="true" stereotype="true" package="true" initial-value="false" signature="true"
|
|
||||||
sort-features="false" accessors="true" visibility="true">
|
|
||||||
<attributes public="true" package="true" protected="true" private="true" static="true"/>
|
|
||||||
<operations public="true" package="true" protected="true" private="true" static="true"/>
|
|
||||||
</display>
|
|
||||||
</interface>
|
|
||||||
<interface id="4" language="java" name="com.iluwatar.abstractdocument.domain.HasParts" project="design-patterns"
|
|
||||||
file="/design-patterns/src/com/iluwatar/abstractdocument/domain/HasParts.java" binary="false" corner="BOTTOM_RIGHT">
|
|
||||||
<position height="81" width="173" x="469" y="194"/>
|
|
||||||
<display autosize="true" stereotype="true" package="true" initial-value="false" signature="true"
|
|
||||||
sort-features="false" accessors="true" visibility="true">
|
|
||||||
<attributes public="true" package="true" protected="true" private="true" static="true"/>
|
|
||||||
<operations public="true" package="true" protected="true" private="true" static="true"/>
|
|
||||||
</display>
|
|
||||||
</interface>
|
|
||||||
<class id="5" language="java" name="com.iluwatar.abstractdocument.domain.Car" project="design-patterns"
|
|
||||||
file="/design-patterns/src/com/iluwatar/abstractdocument/domain/Car.java" binary="false" corner="BOTTOM_RIGHT">
|
|
||||||
<position height="99" width="173" x="254" y="37"/>
|
|
||||||
<display autosize="true" stereotype="true" package="true" initial-value="false" signature="true"
|
<display autosize="true" stereotype="true" package="true" initial-value="false" signature="true"
|
||||||
sort-features="false" accessors="true" visibility="true">
|
sort-features="false" accessors="true" visibility="true">
|
||||||
<attributes public="true" package="true" protected="true" private="true" static="true"/>
|
<attributes public="true" package="true" protected="true" private="true" static="true"/>
|
||||||
<operations public="true" package="true" protected="true" private="true" static="true"/>
|
<operations public="true" package="true" protected="true" private="true" static="true"/>
|
||||||
</display>
|
</display>
|
||||||
</class>
|
</class>
|
||||||
<class id="6" language="java" name="com.iluwatar.abstractdocument.domain.Part" project="design-patterns"
|
<interface id="2" language="java" name="com.iluwatar.abstractdocument.Document" project="abstract-document"
|
||||||
file="/design-patterns/src/com/iluwatar/abstractdocument/domain/Part.java" binary="false" corner="BOTTOM_RIGHT">
|
file="/abstract-document/src/main/java/com/iluwatar/abstractdocument/Document.java" binary="false"
|
||||||
<position height="99" width="173" x="41" y="37"/>
|
corner="BOTTOM_RIGHT">
|
||||||
|
<position height="-1" width="-1" x="562" y="27"/>
|
||||||
|
<display autosize="true" stereotype="true" package="true" initial-value="false" signature="true"
|
||||||
|
sort-features="false" accessors="true" visibility="true">
|
||||||
|
<attributes public="true" package="true" protected="true" private="true" static="true"/>
|
||||||
|
<operations public="true" package="true" protected="true" private="true" static="true"/>
|
||||||
|
</display>
|
||||||
|
</interface>
|
||||||
|
<class id="3" language="java" name="com.iluwatar.abstractdocument.domain.Car" project="abstract-document"
|
||||||
|
file="/abstract-document/src/main/java/com/iluwatar/abstractdocument/domain/Car.java" binary="false"
|
||||||
|
corner="BOTTOM_RIGHT">
|
||||||
|
<position height="-1" width="-1" x="348" y="737"/>
|
||||||
<display autosize="true" stereotype="true" package="true" initial-value="false" signature="true"
|
<display autosize="true" stereotype="true" package="true" initial-value="false" signature="true"
|
||||||
sort-features="false" accessors="true" visibility="true">
|
sort-features="false" accessors="true" visibility="true">
|
||||||
<attributes public="true" package="true" protected="true" private="true" static="true"/>
|
<attributes public="true" package="true" protected="true" private="true" static="true"/>
|
||||||
<operations public="true" package="true" protected="true" private="true" static="true"/>
|
<operations public="true" package="true" protected="true" private="true" static="true"/>
|
||||||
</display>
|
</display>
|
||||||
</class>
|
</class>
|
||||||
<realization id="7">
|
<class id="4" language="java" name="com.iluwatar.abstractdocument.domain.Part" project="abstract-document"
|
||||||
<end type="SOURCE" refId="5"/>
|
file="/abstract-document/src/main/java/com/iluwatar/abstractdocument/domain/Part.java" binary="false"
|
||||||
<end type="TARGET" refId="2"/>
|
corner="BOTTOM_RIGHT">
|
||||||
|
<position height="-1" width="-1" x="760" y="746"/>
|
||||||
|
<display autosize="true" stereotype="true" package="true" initial-value="false" signature="true"
|
||||||
|
sort-features="false" accessors="true" visibility="true">
|
||||||
|
<attributes public="true" package="true" protected="true" private="true" static="true"/>
|
||||||
|
<operations public="true" package="true" protected="true" private="true" static="true"/>
|
||||||
|
</display>
|
||||||
|
</class>
|
||||||
|
<interface id="5" language="java" name="com.iluwatar.abstractdocument.domain.HasModel" project="abstract-document"
|
||||||
|
file="/abstract-document/src/main/java/com/iluwatar/abstractdocument/domain/HasModel.java" binary="false"
|
||||||
|
corner="BOTTOM_RIGHT">
|
||||||
|
<position height="-1" width="-1" x="355" y="297"/>
|
||||||
|
<display autosize="true" stereotype="true" package="true" initial-value="false" signature="true"
|
||||||
|
sort-features="false" accessors="true" visibility="true">
|
||||||
|
<attributes public="true" package="true" protected="true" private="true" static="true"/>
|
||||||
|
<operations public="true" package="true" protected="true" private="true" static="true"/>
|
||||||
|
</display>
|
||||||
|
</interface>
|
||||||
|
<interface id="6" language="java" name="com.iluwatar.abstractdocument.domain.HasParts" project="abstract-document"
|
||||||
|
file="/abstract-document/src/main/java/com/iluwatar/abstractdocument/domain/HasParts.java" binary="false"
|
||||||
|
corner="BOTTOM_RIGHT">
|
||||||
|
<position height="-1" width="-1" x="109" y="297"/>
|
||||||
|
<display autosize="true" stereotype="true" package="true" initial-value="false" signature="true"
|
||||||
|
sort-features="false" accessors="true" visibility="true">
|
||||||
|
<attributes public="true" package="true" protected="true" private="true" static="true"/>
|
||||||
|
<operations public="true" package="true" protected="true" private="true" static="true"/>
|
||||||
|
</display>
|
||||||
|
</interface>
|
||||||
|
<interface id="7" language="java" name="com.iluwatar.abstractdocument.domain.HasPrice" project="abstract-document"
|
||||||
|
file="/abstract-document/src/main/java/com/iluwatar/abstractdocument/domain/HasPrice.java" binary="false"
|
||||||
|
corner="BOTTOM_RIGHT">
|
||||||
|
<position height="-1" width="-1" x="1008" y="283"/>
|
||||||
|
<display autosize="true" stereotype="true" package="true" initial-value="false" signature="true"
|
||||||
|
sort-features="false" accessors="true" visibility="true">
|
||||||
|
<attributes public="true" package="true" protected="true" private="true" static="true"/>
|
||||||
|
<operations public="true" package="true" protected="true" private="true" static="true"/>
|
||||||
|
</display>
|
||||||
|
</interface>
|
||||||
|
<interface id="8" language="java" name="com.iluwatar.abstractdocument.domain.HasType" project="abstract-document"
|
||||||
|
file="/abstract-document/src/main/java/com/iluwatar/abstractdocument/domain/HasType.java" binary="false"
|
||||||
|
corner="BOTTOM_RIGHT">
|
||||||
|
<position height="-1" width="-1" x="1257" y="277"/>
|
||||||
|
<display autosize="true" stereotype="true" package="true" initial-value="false" signature="true"
|
||||||
|
sort-features="false" accessors="true" visibility="true">
|
||||||
|
<attributes public="true" package="true" protected="true" private="true" static="true"/>
|
||||||
|
<operations public="true" package="true" protected="true" private="true" static="true"/>
|
||||||
|
</display>
|
||||||
|
</interface>
|
||||||
|
<realization id="9">
|
||||||
|
<end type="SOURCE" refId="4"/>
|
||||||
|
<end type="TARGET" refId="8"/>
|
||||||
</realization>
|
</realization>
|
||||||
<realization id="8">
|
<realization id="10">
|
||||||
|
<end type="SOURCE" refId="3"/>
|
||||||
|
<end type="TARGET" refId="7"/>
|
||||||
|
</realization>
|
||||||
|
<generalization id="11">
|
||||||
<end type="SOURCE" refId="6"/>
|
<end type="SOURCE" refId="6"/>
|
||||||
<end type="TARGET" refId="2"/>
|
<end type="TARGET" refId="2"/>
|
||||||
</realization>
|
|
||||||
<generalization id="9">
|
|
||||||
<end type="SOURCE" refId="2"/>
|
|
||||||
<end type="TARGET" refId="1"/>
|
|
||||||
</generalization>
|
</generalization>
|
||||||
<realization id="10">
|
<realization id="12">
|
||||||
<end type="SOURCE" refId="5"/>
|
<end type="SOURCE" refId="4"/>
|
||||||
<end type="TARGET" refId="3"/>
|
<end type="TARGET" refId="5"/>
|
||||||
</realization>
|
</realization>
|
||||||
<realization id="11">
|
<realization id="13">
|
||||||
<end type="SOURCE" refId="5"/>
|
<end type="SOURCE" refId="4"/>
|
||||||
<end type="TARGET" refId="4"/>
|
<end type="TARGET" refId="7"/>
|
||||||
</realization>
|
</realization>
|
||||||
<generalization id="12">
|
<generalization id="14">
|
||||||
<end type="SOURCE" refId="3"/>
|
<end type="SOURCE" refId="3"/>
|
||||||
<end type="TARGET" refId="1"/>
|
<end type="TARGET" refId="1"/>
|
||||||
</generalization>
|
</generalization>
|
||||||
<generalization id="13">
|
<realization id="15">
|
||||||
|
<end type="SOURCE" refId="3"/>
|
||||||
|
<end type="TARGET" refId="6"/>
|
||||||
|
</realization>
|
||||||
|
<generalization id="16">
|
||||||
|
<end type="SOURCE" refId="8"/>
|
||||||
|
<end type="TARGET" refId="2"/>
|
||||||
|
</generalization>
|
||||||
|
<generalization id="17">
|
||||||
|
<end type="SOURCE" refId="7"/>
|
||||||
|
<end type="TARGET" refId="2"/>
|
||||||
|
</generalization>
|
||||||
|
<realization id="18">
|
||||||
|
<end type="SOURCE" refId="3"/>
|
||||||
|
<end type="TARGET" refId="5"/>
|
||||||
|
</realization>
|
||||||
|
<generalization id="19">
|
||||||
<end type="SOURCE" refId="4"/>
|
<end type="SOURCE" refId="4"/>
|
||||||
<end type="TARGET" refId="1"/>
|
<end type="TARGET" refId="1"/>
|
||||||
</generalization>
|
</generalization>
|
||||||
<realization id="14">
|
<generalization id="20">
|
||||||
<end type="SOURCE" refId="6"/>
|
<end type="SOURCE" refId="5"/>
|
||||||
<end type="TARGET" refId="3"/>
|
<end type="TARGET" refId="2"/>
|
||||||
|
</generalization>
|
||||||
|
<realization id="21">
|
||||||
|
<end type="SOURCE" refId="1"/>
|
||||||
|
<end type="TARGET" refId="2"/>
|
||||||
</realization>
|
</realization>
|
||||||
<classifier-display autosize="true" stereotype="true" package="true" initial-value="false" signature="true"
|
<classifier-display autosize="true" stereotype="true" package="true" initial-value="false" signature="true"
|
||||||
sort-features="false" accessors="true" visibility="true">
|
sort-features="false" accessors="true" visibility="true">
|
||||||
|
@ -29,7 +29,7 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<artifactId>java-design-patterns</artifactId>
|
<artifactId>java-design-patterns</artifactId>
|
||||||
<groupId>com.iluwatar</groupId>
|
<groupId>com.iluwatar</groupId>
|
||||||
<version>1.18.0</version>
|
<version>1.19.0</version>
|
||||||
</parent>
|
</parent>
|
||||||
<artifactId>abstract-document</artifactId>
|
<artifactId>abstract-document</artifactId>
|
||||||
<dependencies>
|
<dependencies>
|
||||||
|
@ -34,7 +34,7 @@ Wikipedia says
|
|||||||
|
|
||||||
Translating the kingdom example above. First of all we have some interfaces and implementation for the objects in the kingdom
|
Translating the kingdom example above. First of all we have some interfaces and implementation for the objects in the kingdom
|
||||||
|
|
||||||
```
|
```java
|
||||||
public interface Castle {
|
public interface Castle {
|
||||||
String getDescription();
|
String getDescription();
|
||||||
}
|
}
|
||||||
@ -74,7 +74,7 @@ public class ElfArmy implements Army {
|
|||||||
|
|
||||||
Then we have the abstraction and implementations for the kingdom factory
|
Then we have the abstraction and implementations for the kingdom factory
|
||||||
|
|
||||||
```
|
```java
|
||||||
public interface KingdomFactory {
|
public interface KingdomFactory {
|
||||||
Castle createCastle();
|
Castle createCastle();
|
||||||
King createKing();
|
King createKing();
|
||||||
@ -108,7 +108,7 @@ public class OrcKingdomFactory implements KingdomFactory {
|
|||||||
|
|
||||||
Now we have our abstract factory that lets us make family of related objects i.e. Elven kingdom factory creates Elven castle, king and army etc.
|
Now we have our abstract factory that lets us make family of related objects i.e. Elven kingdom factory creates Elven castle, king and army etc.
|
||||||
|
|
||||||
```
|
```java
|
||||||
KingdomFactory factory = new ElfKingdomFactory();
|
KingdomFactory factory = new ElfKingdomFactory();
|
||||||
Castle castle = factory.createCastle();
|
Castle castle = factory.createCastle();
|
||||||
King king = factory.createKing();
|
King king = factory.createKing();
|
||||||
@ -123,7 +123,7 @@ Now, we can design a factory for our different kingdom factories. In this exampl
|
|||||||
The client can use FactoryMaker to create the desired concrete factory which, in turn, will produce different concrete objects (Army, King, Castle).
|
The client can use FactoryMaker to create the desired concrete factory which, in turn, will produce different concrete objects (Army, King, Castle).
|
||||||
In this example, we also used an enum to parameterize which type of kingdom factory the client will ask for.
|
In this example, we also used an enum to parameterize which type of kingdom factory the client will ask for.
|
||||||
|
|
||||||
```
|
```java
|
||||||
public static class FactoryMaker {
|
public static class FactoryMaker {
|
||||||
|
|
||||||
public enum KingdomType {
|
public enum KingdomType {
|
||||||
@ -179,10 +179,15 @@ Use the Abstract Factory pattern when
|
|||||||
|
|
||||||
* Dependency injection in java hides the service class dependencies that can lead to runtime errors that would have been caught at compile time.
|
* Dependency injection in java hides the service class dependencies that can lead to runtime errors that would have been caught at compile time.
|
||||||
|
|
||||||
|
|
||||||
|
## Tutorial
|
||||||
|
* [Abstract Factory Pattern Tutorial](https://www.journaldev.com/1418/abstract-factory-design-pattern-in-java)
|
||||||
|
|
||||||
## Presentations
|
## Presentations
|
||||||
|
|
||||||
* [Abstract Factory Pattern](etc/presentation.html)
|
* [Abstract Factory Pattern](etc/presentation.html)
|
||||||
|
|
||||||
|
|
||||||
## Real world examples
|
## Real world examples
|
||||||
|
|
||||||
* [javax.xml.parsers.DocumentBuilderFactory](http://docs.oracle.com/javase/8/docs/api/javax/xml/parsers/DocumentBuilderFactory.html)
|
* [javax.xml.parsers.DocumentBuilderFactory](http://docs.oracle.com/javase/8/docs/api/javax/xml/parsers/DocumentBuilderFactory.html)
|
||||||
|
@ -29,7 +29,7 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<groupId>com.iluwatar</groupId>
|
<groupId>com.iluwatar</groupId>
|
||||||
<artifactId>java-design-patterns</artifactId>
|
<artifactId>java-design-patterns</artifactId>
|
||||||
<version>1.18.0</version>
|
<version>1.19.0</version>
|
||||||
</parent>
|
</parent>
|
||||||
<artifactId>abstract-factory</artifactId>
|
<artifactId>abstract-factory</artifactId>
|
||||||
<dependencies>
|
<dependencies>
|
||||||
|
@ -40,7 +40,7 @@ Consider a captain that can only use rowing boats and cannot sail at all.
|
|||||||
|
|
||||||
First we have interfaces `RowingBoat` and `FishingBoat`
|
First we have interfaces `RowingBoat` and `FishingBoat`
|
||||||
|
|
||||||
```
|
```java
|
||||||
public interface RowingBoat {
|
public interface RowingBoat {
|
||||||
void row();
|
void row();
|
||||||
}
|
}
|
||||||
@ -55,7 +55,7 @@ public class FishingBoat {
|
|||||||
|
|
||||||
And captain expects an implementation of `RowingBoat` interface to be able to move
|
And captain expects an implementation of `RowingBoat` interface to be able to move
|
||||||
|
|
||||||
```
|
```java
|
||||||
public class Captain implements RowingBoat {
|
public class Captain implements RowingBoat {
|
||||||
|
|
||||||
private RowingBoat rowingBoat;
|
private RowingBoat rowingBoat;
|
||||||
@ -73,7 +73,7 @@ public class Captain implements RowingBoat {
|
|||||||
|
|
||||||
Now let's say the pirates are coming and our captain needs to escape but there is only fishing boat available. We need to create an adapter that allows the captain to operate the fishing boat with his rowing boat skills.
|
Now let's say the pirates are coming and our captain needs to escape but there is only fishing boat available. We need to create an adapter that allows the captain to operate the fishing boat with his rowing boat skills.
|
||||||
|
|
||||||
```
|
```java
|
||||||
public class FishingBoatAdapter implements RowingBoat {
|
public class FishingBoatAdapter implements RowingBoat {
|
||||||
|
|
||||||
private static final Logger LOGGER = LoggerFactory.getLogger(FishingBoatAdapter.class);
|
private static final Logger LOGGER = LoggerFactory.getLogger(FishingBoatAdapter.class);
|
||||||
@ -93,7 +93,7 @@ public class FishingBoatAdapter implements RowingBoat {
|
|||||||
|
|
||||||
And now the `Captain` can use the `FishingBoat` to escape the pirates.
|
And now the `Captain` can use the `FishingBoat` to escape the pirates.
|
||||||
|
|
||||||
```
|
```java
|
||||||
Captain captain = new Captain(new FishingBoatAdapter());
|
Captain captain = new Captain(new FishingBoatAdapter());
|
||||||
captain.row();
|
captain.row();
|
||||||
```
|
```
|
||||||
|
@ -29,7 +29,7 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<groupId>com.iluwatar</groupId>
|
<groupId>com.iluwatar</groupId>
|
||||||
<artifactId>java-design-patterns</artifactId>
|
<artifactId>java-design-patterns</artifactId>
|
||||||
<version>1.18.0</version>
|
<version>1.19.0</version>
|
||||||
</parent>
|
</parent>
|
||||||
<artifactId>adapter</artifactId>
|
<artifactId>adapter</artifactId>
|
||||||
<dependencies>
|
<dependencies>
|
||||||
|
@ -26,7 +26,7 @@ package com.iluwatar.adapter;
|
|||||||
* The Captain uses {@link RowingBoat} to sail. <br>
|
* The Captain uses {@link RowingBoat} to sail. <br>
|
||||||
* This is the client in the pattern.
|
* This is the client in the pattern.
|
||||||
*/
|
*/
|
||||||
public class Captain implements RowingBoat {
|
public class Captain {
|
||||||
|
|
||||||
private RowingBoat rowingBoat;
|
private RowingBoat rowingBoat;
|
||||||
|
|
||||||
@ -40,7 +40,6 @@ public class Captain implements RowingBoat {
|
|||||||
this.rowingBoat = rowingBoat;
|
this.rowingBoat = rowingBoat;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void row() {
|
public void row() {
|
||||||
rowingBoat.row();
|
rowingBoat.row();
|
||||||
}
|
}
|
||||||
|
@ -66,7 +66,7 @@ public class AdapterPatternTest {
|
|||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
public void testAdapter() {
|
public void testAdapter() {
|
||||||
RowingBoat captain = (RowingBoat) beans.get(ROWING_BEAN);
|
Captain captain = (Captain) beans.get(ROWING_BEAN);
|
||||||
|
|
||||||
// when captain moves
|
// when captain moves
|
||||||
captain.row();
|
captain.row();
|
||||||
|
@ -29,7 +29,7 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<artifactId>aggregator-microservices</artifactId>
|
<artifactId>aggregator-microservices</artifactId>
|
||||||
<groupId>com.iluwatar</groupId>
|
<groupId>com.iluwatar</groupId>
|
||||||
<version>1.18.0</version>
|
<version>1.19.0</version>
|
||||||
</parent>
|
</parent>
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
|
||||||
|
@ -29,7 +29,7 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<artifactId>aggregator-microservices</artifactId>
|
<artifactId>aggregator-microservices</artifactId>
|
||||||
<groupId>com.iluwatar</groupId>
|
<groupId>com.iluwatar</groupId>
|
||||||
<version>1.18.0</version>
|
<version>1.19.0</version>
|
||||||
</parent>
|
</parent>
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
|
||||||
|
@ -29,7 +29,7 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<artifactId>aggregator-microservices</artifactId>
|
<artifactId>aggregator-microservices</artifactId>
|
||||||
<groupId>com.iluwatar</groupId>
|
<groupId>com.iluwatar</groupId>
|
||||||
<version>1.18.0</version>
|
<version>1.19.0</version>
|
||||||
</parent>
|
</parent>
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
|
||||||
|
@ -29,7 +29,7 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<artifactId>java-design-patterns</artifactId>
|
<artifactId>java-design-patterns</artifactId>
|
||||||
<groupId>com.iluwatar</groupId>
|
<groupId>com.iluwatar</groupId>
|
||||||
<version>1.18.0</version>
|
<version>1.19.0</version>
|
||||||
</parent>
|
</parent>
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
<artifactId>aggregator-microservices</artifactId>
|
<artifactId>aggregator-microservices</artifactId>
|
||||||
|
@ -29,7 +29,7 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<artifactId>api-gateway</artifactId>
|
<artifactId>api-gateway</artifactId>
|
||||||
<groupId>com.iluwatar</groupId>
|
<groupId>com.iluwatar</groupId>
|
||||||
<version>1.18.0</version>
|
<version>1.19.0</version>
|
||||||
</parent>
|
</parent>
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
<artifactId>api-gateway-service</artifactId>
|
<artifactId>api-gateway-service</artifactId>
|
||||||
|
@ -29,7 +29,7 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<artifactId>api-gateway</artifactId>
|
<artifactId>api-gateway</artifactId>
|
||||||
<groupId>com.iluwatar</groupId>
|
<groupId>com.iluwatar</groupId>
|
||||||
<version>1.18.0</version>
|
<version>1.19.0</version>
|
||||||
</parent>
|
</parent>
|
||||||
|
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
@ -29,7 +29,7 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<artifactId>java-design-patterns</artifactId>
|
<artifactId>java-design-patterns</artifactId>
|
||||||
<groupId>com.iluwatar</groupId>
|
<groupId>com.iluwatar</groupId>
|
||||||
<version>1.18.0</version>
|
<version>1.19.0</version>
|
||||||
</parent>
|
</parent>
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
<artifactId>api-gateway</artifactId>
|
<artifactId>api-gateway</artifactId>
|
||||||
|
@ -29,7 +29,7 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<artifactId>api-gateway</artifactId>
|
<artifactId>api-gateway</artifactId>
|
||||||
<groupId>com.iluwatar</groupId>
|
<groupId>com.iluwatar</groupId>
|
||||||
<version>1.18.0</version>
|
<version>1.19.0</version>
|
||||||
</parent>
|
</parent>
|
||||||
|
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
@ -29,7 +29,7 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<groupId>com.iluwatar</groupId>
|
<groupId>com.iluwatar</groupId>
|
||||||
<artifactId>java-design-patterns</artifactId>
|
<artifactId>java-design-patterns</artifactId>
|
||||||
<version>1.18.0</version>
|
<version>1.19.0</version>
|
||||||
</parent>
|
</parent>
|
||||||
<artifactId>async-method-invocation</artifactId>
|
<artifactId>async-method-invocation</artifactId>
|
||||||
<dependencies>
|
<dependencies>
|
||||||
|
@ -29,7 +29,7 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<artifactId>java-design-patterns</artifactId>
|
<artifactId>java-design-patterns</artifactId>
|
||||||
<groupId>com.iluwatar</groupId>
|
<groupId>com.iluwatar</groupId>
|
||||||
<version>1.18.0</version>
|
<version>1.19.0</version>
|
||||||
</parent>
|
</parent>
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
|
||||||
|
@ -22,6 +22,7 @@
|
|||||||
*/
|
*/
|
||||||
package com.iluwatar.balking;
|
package com.iluwatar.balking;
|
||||||
|
|
||||||
|
import org.junit.jupiter.api.Disabled;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
import java.util.concurrent.ExecutorService;
|
import java.util.concurrent.ExecutorService;
|
||||||
@ -37,6 +38,7 @@ public class WashingMachineTest {
|
|||||||
|
|
||||||
private volatile WashingMachineState machineStateGlobal;
|
private volatile WashingMachineState machineStateGlobal;
|
||||||
|
|
||||||
|
@Disabled
|
||||||
@Test
|
@Test
|
||||||
public void wash() throws Exception {
|
public void wash() throws Exception {
|
||||||
WashingMachine washingMachine = new WashingMachine();
|
WashingMachine washingMachine = new WashingMachine();
|
||||||
|
@ -34,7 +34,7 @@ Wikipedia says
|
|||||||
|
|
||||||
Translating our weapon example from above. Here we have the `Weapon` hierarchy
|
Translating our weapon example from above. Here we have the `Weapon` hierarchy
|
||||||
|
|
||||||
```
|
```java
|
||||||
public interface Weapon {
|
public interface Weapon {
|
||||||
void wield();
|
void wield();
|
||||||
void swing();
|
void swing();
|
||||||
@ -109,7 +109,7 @@ public class Hammer implements Weapon {
|
|||||||
|
|
||||||
And the separate enchantment hierarchy
|
And the separate enchantment hierarchy
|
||||||
|
|
||||||
```
|
```java
|
||||||
public interface Enchantment {
|
public interface Enchantment {
|
||||||
void onActivate();
|
void onActivate();
|
||||||
void apply();
|
void apply();
|
||||||
@ -155,7 +155,7 @@ public class SoulEatingEnchantment implements Enchantment {
|
|||||||
|
|
||||||
And both the hierarchies in action
|
And both the hierarchies in action
|
||||||
|
|
||||||
```
|
```java
|
||||||
Sword enchantedSword = new Sword(new SoulEatingEnchantment());
|
Sword enchantedSword = new Sword(new SoulEatingEnchantment());
|
||||||
enchantedSword.wield();
|
enchantedSword.wield();
|
||||||
enchantedSword.swing();
|
enchantedSword.swing();
|
||||||
@ -188,6 +188,9 @@ Use the Bridge pattern when
|
|||||||
* you have a proliferation of classes. Such a class hierarchy indicates the need for splitting an object into two parts. Rumbaugh uses the term "nested generalizations" to refer to such class hierarchies
|
* you have a proliferation of classes. Such a class hierarchy indicates the need for splitting an object into two parts. Rumbaugh uses the term "nested generalizations" to refer to such class hierarchies
|
||||||
* you want to share an implementation among multiple objects (perhaps using reference counting), and this fact should be hidden from the client. A simple example is Coplien's String class, in which multiple objects can share the same string representation.
|
* you want to share an implementation among multiple objects (perhaps using reference counting), and this fact should be hidden from the client. A simple example is Coplien's String class, in which multiple objects can share the same string representation.
|
||||||
|
|
||||||
|
## Tutorial
|
||||||
|
* [Bridge Pattern Tutorial](https://www.journaldev.com/1491/bridge-design-pattern-java)
|
||||||
|
|
||||||
## Credits
|
## Credits
|
||||||
|
|
||||||
* [Design Patterns: Elements of Reusable Object-Oriented Software](http://www.amazon.com/Design-Patterns-Elements-Reusable-Object-Oriented/dp/0201633612)
|
* [Design Patterns: Elements of Reusable Object-Oriented Software](http://www.amazon.com/Design-Patterns-Elements-Reusable-Object-Oriented/dp/0201633612)
|
||||||
|
@ -29,7 +29,7 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<groupId>com.iluwatar</groupId>
|
<groupId>com.iluwatar</groupId>
|
||||||
<artifactId>java-design-patterns</artifactId>
|
<artifactId>java-design-patterns</artifactId>
|
||||||
<version>1.18.0</version>
|
<version>1.19.0</version>
|
||||||
</parent>
|
</parent>
|
||||||
<artifactId>bridge</artifactId>
|
<artifactId>bridge</artifactId>
|
||||||
<dependencies>
|
<dependencies>
|
||||||
|
@ -31,7 +31,7 @@ Wikipedia says
|
|||||||
|
|
||||||
Having said that let me add a bit about what telescoping constructor anti-pattern is. At one point or the other we have all seen a constructor like below:
|
Having said that let me add a bit about what telescoping constructor anti-pattern is. At one point or the other we have all seen a constructor like below:
|
||||||
|
|
||||||
```
|
```java
|
||||||
public Hero(Profession profession, String name, HairType hairType, HairColor hairColor, Armor armor, Weapon weapon) {
|
public Hero(Profession profession, String name, HairType hairType, HairColor hairColor, Armor armor, Weapon weapon) {
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
@ -42,7 +42,7 @@ As you can see the number of constructor parameters can quickly get out of hand
|
|||||||
|
|
||||||
The sane alternative is to use the Builder pattern. First of all we have our hero that we want to create
|
The sane alternative is to use the Builder pattern. First of all we have our hero that we want to create
|
||||||
|
|
||||||
```
|
```java
|
||||||
public final class Hero {
|
public final class Hero {
|
||||||
private final Profession profession;
|
private final Profession profession;
|
||||||
private final String name;
|
private final String name;
|
||||||
@ -64,7 +64,7 @@ public final class Hero {
|
|||||||
|
|
||||||
And then we have the builder
|
And then we have the builder
|
||||||
|
|
||||||
```
|
```java
|
||||||
public static class Builder {
|
public static class Builder {
|
||||||
private final Profession profession;
|
private final Profession profession;
|
||||||
private final String name;
|
private final String name;
|
||||||
@ -109,7 +109,7 @@ And then we have the builder
|
|||||||
|
|
||||||
And then it can be used as:
|
And then it can be used as:
|
||||||
|
|
||||||
```
|
```java
|
||||||
Hero mage = new Hero.Builder(Profession.MAGE, "Riobard").withHairColor(HairColor.BLACK).withWeapon(Weapon.DAGGER).build();
|
Hero mage = new Hero.Builder(Profession.MAGE, "Riobard").withHairColor(HairColor.BLACK).withWeapon(Weapon.DAGGER).build();
|
||||||
```
|
```
|
||||||
|
|
||||||
|
@ -29,7 +29,7 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<groupId>com.iluwatar</groupId>
|
<groupId>com.iluwatar</groupId>
|
||||||
<artifactId>java-design-patterns</artifactId>
|
<artifactId>java-design-patterns</artifactId>
|
||||||
<version>1.18.0</version>
|
<version>1.19.0</version>
|
||||||
</parent>
|
</parent>
|
||||||
<artifactId>builder</artifactId>
|
<artifactId>builder</artifactId>
|
||||||
<dependencies>
|
<dependencies>
|
||||||
|
@ -30,7 +30,7 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<groupId>com.iluwatar</groupId>
|
<groupId>com.iluwatar</groupId>
|
||||||
<artifactId>java-design-patterns</artifactId>
|
<artifactId>java-design-patterns</artifactId>
|
||||||
<version>1.18.0</version>
|
<version>1.19.0</version>
|
||||||
</parent>
|
</parent>
|
||||||
<artifactId>business-delegate</artifactId>
|
<artifactId>business-delegate</artifactId>
|
||||||
<dependencies>
|
<dependencies>
|
||||||
|
@ -29,7 +29,7 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<groupId>com.iluwatar</groupId>
|
<groupId>com.iluwatar</groupId>
|
||||||
<artifactId>java-design-patterns</artifactId>
|
<artifactId>java-design-patterns</artifactId>
|
||||||
<version>1.18.0</version>
|
<version>1.19.0</version>
|
||||||
</parent>
|
</parent>
|
||||||
<artifactId>caching</artifactId>
|
<artifactId>caching</artifactId>
|
||||||
<dependencies>
|
<dependencies>
|
||||||
|
@ -52,12 +52,12 @@ import org.slf4j.LoggerFactory;
|
|||||||
* whether the data is coming from the cache or the DB (i.e. separation of concern). The AppManager
|
* whether the data is coming from the cache or the DB (i.e. separation of concern). The AppManager
|
||||||
* ({@link AppManager}) handles the transaction of data to-and-from the underlying data store
|
* ({@link AppManager}) handles the transaction of data to-and-from the underlying data store
|
||||||
* (depending on the preferred caching policy/strategy).
|
* (depending on the preferred caching policy/strategy).
|
||||||
*
|
* <p>
|
||||||
* <i>App --> AppManager --> CacheStore/LRUCache/CachingPolicy --> DBManager</i>
|
* <i>{@literal App --> AppManager --> CacheStore/LRUCache/CachingPolicy --> DBManager} </i>
|
||||||
* </p>
|
* </p>
|
||||||
*
|
*
|
||||||
* @see CacheStore
|
* @see CacheStore
|
||||||
* @See LRUCache
|
* @see LruCache
|
||||||
* @see CachingPolicy
|
* @see CachingPolicy
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
@ -29,7 +29,7 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<groupId>com.iluwatar</groupId>
|
<groupId>com.iluwatar</groupId>
|
||||||
<artifactId>java-design-patterns</artifactId>
|
<artifactId>java-design-patterns</artifactId>
|
||||||
<version>1.18.0</version>
|
<version>1.19.0</version>
|
||||||
</parent>
|
</parent>
|
||||||
<artifactId>callback</artifactId>
|
<artifactId>callback</artifactId>
|
||||||
<dependencies>
|
<dependencies>
|
||||||
|
@ -33,7 +33,7 @@ Wikipedia says
|
|||||||
|
|
||||||
Translating our example with orcs from above. First we have the request class
|
Translating our example with orcs from above. First we have the request class
|
||||||
|
|
||||||
```
|
```java
|
||||||
public class Request {
|
public class Request {
|
||||||
|
|
||||||
private final RequestType requestType;
|
private final RequestType requestType;
|
||||||
@ -64,7 +64,7 @@ public enum RequestType {
|
|||||||
|
|
||||||
Then the request handler hierarchy
|
Then the request handler hierarchy
|
||||||
|
|
||||||
```
|
```java
|
||||||
public abstract class RequestHandler {
|
public abstract class RequestHandler {
|
||||||
private static final Logger LOGGER = LoggerFactory.getLogger(RequestHandler.class);
|
private static final Logger LOGGER = LoggerFactory.getLogger(RequestHandler.class);
|
||||||
private RequestHandler next;
|
private RequestHandler next;
|
||||||
@ -114,7 +114,7 @@ public class OrcCommander extends RequestHandler {
|
|||||||
|
|
||||||
Then we have the Orc King who gives the orders and forms the chain
|
Then we have the Orc King who gives the orders and forms the chain
|
||||||
|
|
||||||
```
|
```java
|
||||||
public class OrcKing {
|
public class OrcKing {
|
||||||
RequestHandler chain;
|
RequestHandler chain;
|
||||||
|
|
||||||
@ -134,7 +134,7 @@ public class OrcKing {
|
|||||||
|
|
||||||
Then it is used as follows
|
Then it is used as follows
|
||||||
|
|
||||||
```
|
```java
|
||||||
OrcKing king = new OrcKing();
|
OrcKing king = new OrcKing();
|
||||||
king.makeRequest(new Request(RequestType.DEFEND_CASTLE, "defend castle")); // Orc commander handling request "defend castle"
|
king.makeRequest(new Request(RequestType.DEFEND_CASTLE, "defend castle")); // Orc commander handling request "defend castle"
|
||||||
king.makeRequest(new Request(RequestType.TORTURE_PRISONER, "torture prisoner")); // Orc officer handling request "torture prisoner"
|
king.makeRequest(new Request(RequestType.TORTURE_PRISONER, "torture prisoner")); // Orc officer handling request "torture prisoner"
|
||||||
|
@ -29,7 +29,7 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<groupId>com.iluwatar</groupId>
|
<groupId>com.iluwatar</groupId>
|
||||||
<artifactId>java-design-patterns</artifactId>
|
<artifactId>java-design-patterns</artifactId>
|
||||||
<version>1.18.0</version>
|
<version>1.19.0</version>
|
||||||
</parent>
|
</parent>
|
||||||
<artifactId>chain</artifactId>
|
<artifactId>chain</artifactId>
|
||||||
<dependencies>
|
<dependencies>
|
||||||
|
@ -29,7 +29,7 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<groupId>com.iluwatar</groupId>
|
<groupId>com.iluwatar</groupId>
|
||||||
<artifactId>java-design-patterns</artifactId>
|
<artifactId>java-design-patterns</artifactId>
|
||||||
<version>1.18.0</version>
|
<version>1.19.0</version>
|
||||||
</parent>
|
</parent>
|
||||||
<artifactId>command</artifactId>
|
<artifactId>command</artifactId>
|
||||||
<dependencies>
|
<dependencies>
|
||||||
|
@ -33,7 +33,7 @@ Wikipedia says
|
|||||||
|
|
||||||
Taking our sentence example from above. Here we have the base class and different printable types
|
Taking our sentence example from above. Here we have the base class and different printable types
|
||||||
|
|
||||||
```
|
```java
|
||||||
public abstract class LetterComposite {
|
public abstract class LetterComposite {
|
||||||
private List<LetterComposite> children = new ArrayList<>();
|
private List<LetterComposite> children = new ArrayList<>();
|
||||||
public void add(LetterComposite letter) {
|
public void add(LetterComposite letter) {
|
||||||
@ -91,7 +91,7 @@ public class Sentence extends LetterComposite {
|
|||||||
|
|
||||||
Then we have a messenger to carry messages
|
Then we have a messenger to carry messages
|
||||||
|
|
||||||
```
|
```java
|
||||||
public class Messenger {
|
public class Messenger {
|
||||||
LetterComposite messageFromOrcs() {
|
LetterComposite messageFromOrcs() {
|
||||||
List<Word> words = new ArrayList<>();
|
List<Word> words = new ArrayList<>();
|
||||||
@ -122,7 +122,7 @@ public class Messenger {
|
|||||||
|
|
||||||
And then it can be used as
|
And then it can be used as
|
||||||
|
|
||||||
```
|
```java
|
||||||
LetterComposite orcMessage = new Messenger().messageFromOrcs();
|
LetterComposite orcMessage = new Messenger().messageFromOrcs();
|
||||||
orcMessage.print(); // Where there is a whip there is a way.
|
orcMessage.print(); // Where there is a whip there is a way.
|
||||||
LetterComposite elfMessage = new Messenger().messageFromElves();
|
LetterComposite elfMessage = new Messenger().messageFromElves();
|
||||||
|
@ -29,7 +29,7 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<groupId>com.iluwatar</groupId>
|
<groupId>com.iluwatar</groupId>
|
||||||
<artifactId>java-design-patterns</artifactId>
|
<artifactId>java-design-patterns</artifactId>
|
||||||
<version>1.18.0</version>
|
<version>1.19.0</version>
|
||||||
</parent>
|
</parent>
|
||||||
<artifactId>composite</artifactId>
|
<artifactId>composite</artifactId>
|
||||||
<dependencies>
|
<dependencies>
|
||||||
|
@ -29,7 +29,7 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<artifactId>java-design-patterns</artifactId>
|
<artifactId>java-design-patterns</artifactId>
|
||||||
<groupId>com.iluwatar</groupId>
|
<groupId>com.iluwatar</groupId>
|
||||||
<version>1.18.0</version>
|
<version>1.19.0</version>
|
||||||
</parent>
|
</parent>
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
<dependencies>
|
<dependencies>
|
||||||
|
@ -21,7 +21,7 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<groupId>com.iluwatar</groupId>
|
<groupId>com.iluwatar</groupId>
|
||||||
<artifactId>java-design-patterns</artifactId>
|
<artifactId>java-design-patterns</artifactId>
|
||||||
<version>1.18.0</version>
|
<version>1.19.0</version>
|
||||||
</parent>
|
</parent>
|
||||||
<artifactId>cqrs</artifactId>
|
<artifactId>cqrs</artifactId>
|
||||||
<dependencies>
|
<dependencies>
|
||||||
|
@ -50,14 +50,12 @@ public class Author {
|
|||||||
* email of the author
|
* email of the author
|
||||||
*/
|
*/
|
||||||
public Author(String username, String name, String email) {
|
public Author(String username, String name, String email) {
|
||||||
super();
|
|
||||||
this.username = username;
|
this.username = username;
|
||||||
this.name = name;
|
this.name = name;
|
||||||
this.email = email;
|
this.email = email;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected Author() {
|
protected Author() {
|
||||||
super();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public long getId() {
|
public long getId() {
|
||||||
|
@ -43,7 +43,7 @@ public class Book {
|
|||||||
private Author author;
|
private Author author;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @param title
|
* @param title
|
||||||
* title of the book
|
* title of the book
|
||||||
* @param price
|
* @param price
|
||||||
@ -52,14 +52,12 @@ public class Book {
|
|||||||
* author of the book
|
* author of the book
|
||||||
*/
|
*/
|
||||||
public Book(String title, double price, Author author) {
|
public Book(String title, double price, Author author) {
|
||||||
super();
|
|
||||||
this.title = title;
|
this.title = title;
|
||||||
this.price = price;
|
this.price = price;
|
||||||
this.author = author;
|
this.author = author;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected Book() {
|
protected Book() {
|
||||||
super();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public long getId() {
|
public long getId() {
|
||||||
|
@ -45,14 +45,12 @@ public class Author {
|
|||||||
* username of the author
|
* username of the author
|
||||||
*/
|
*/
|
||||||
public Author(String name, String email, String username) {
|
public Author(String name, String email, String username) {
|
||||||
super();
|
|
||||||
this.name = name;
|
this.name = name;
|
||||||
this.email = email;
|
this.email = email;
|
||||||
this.username = username;
|
this.username = username;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Author() {
|
public Author() {
|
||||||
super();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getName() {
|
public String getName() {
|
||||||
|
@ -42,13 +42,11 @@ public class Book {
|
|||||||
* price of the book
|
* price of the book
|
||||||
*/
|
*/
|
||||||
public Book(String title, double price) {
|
public Book(String title, double price) {
|
||||||
super();
|
|
||||||
this.title = title;
|
this.title = title;
|
||||||
this.price = price;
|
this.price = price;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Book() {
|
public Book() {
|
||||||
super();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getTitle() {
|
public String getTitle() {
|
||||||
|
@ -30,7 +30,7 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<groupId>com.iluwatar</groupId>
|
<groupId>com.iluwatar</groupId>
|
||||||
<artifactId>java-design-patterns</artifactId>
|
<artifactId>java-design-patterns</artifactId>
|
||||||
<version>1.18.0</version>
|
<version>1.19.0</version>
|
||||||
</parent>
|
</parent>
|
||||||
<artifactId>dao</artifactId>
|
<artifactId>dao</artifactId>
|
||||||
|
|
||||||
|
@ -31,7 +31,7 @@ import java.util.stream.Stream;
|
|||||||
/**
|
/**
|
||||||
* An in memory implementation of {@link CustomerDao}, which stores the customers in JVM memory
|
* An in memory implementation of {@link CustomerDao}, which stores the customers in JVM memory
|
||||||
* and data is lost when the application exits.
|
* and data is lost when the application exits.
|
||||||
* <br/>
|
* <br>
|
||||||
* This implementation is useful as temporary database or for testing.
|
* This implementation is useful as temporary database or for testing.
|
||||||
*/
|
*/
|
||||||
public class InMemoryCustomerDao implements CustomerDao {
|
public class InMemoryCustomerDao implements CustomerDao {
|
||||||
|
@ -185,8 +185,7 @@ public class DbCustomerDaoTest {
|
|||||||
public class ConnectivityIssue {
|
public class ConnectivityIssue {
|
||||||
|
|
||||||
private static final String EXCEPTION_CAUSE = "Connection not available";
|
private static final String EXCEPTION_CAUSE = "Connection not available";
|
||||||
//@Rule public ExpectedException exception = ExpectedException.none();
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* setup a connection failure scenario.
|
* setup a connection failure scenario.
|
||||||
* @throws SQLException if any error occurs.
|
* @throws SQLException if any error occurs.
|
||||||
@ -194,8 +193,6 @@ public class DbCustomerDaoTest {
|
|||||||
@BeforeEach
|
@BeforeEach
|
||||||
public void setUp() throws SQLException {
|
public void setUp() throws SQLException {
|
||||||
dao = new DbCustomerDao(mockedDatasource());
|
dao = new DbCustomerDao(mockedDatasource());
|
||||||
//exception.expect(Exception.class);
|
|
||||||
//exception.expectMessage(EXCEPTION_CAUSE);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private DataSource mockedDatasource() throws SQLException {
|
private DataSource mockedDatasource() throws SQLException {
|
||||||
|
@ -33,7 +33,7 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<groupId>com.iluwatar</groupId>
|
<groupId>com.iluwatar</groupId>
|
||||||
<artifactId>java-design-patterns</artifactId>
|
<artifactId>java-design-patterns</artifactId>
|
||||||
<version>1.18.0</version>
|
<version>1.19.0</version>
|
||||||
</parent>
|
</parent>
|
||||||
<artifactId>data-bus</artifactId>
|
<artifactId>data-bus</artifactId>
|
||||||
<dependencies>
|
<dependencies>
|
||||||
|
@ -34,8 +34,7 @@ import java.time.LocalDateTime;
|
|||||||
/**
|
/**
|
||||||
* The Data Bus pattern
|
* The Data Bus pattern
|
||||||
* <p>
|
* <p>
|
||||||
* <p>{@see http://wiki.c2.com/?DataBusPattern}</p>
|
* @see <a href="http://wiki.c2.com/?DataBusPattern">http://wiki.c2.com/?DataBusPattern</a>
|
||||||
* <p>
|
|
||||||
* <p>The Data-Bus pattern provides a method where different parts of an application may
|
* <p>The Data-Bus pattern provides a method where different parts of an application may
|
||||||
* pass messages between each other without needing to be aware of the other's existence.</p>
|
* pass messages between each other without needing to be aware of the other's existence.</p>
|
||||||
* <p>Similar to the {@code ObserverPattern}, members register themselves with the {@link DataBus}
|
* <p>Similar to the {@code ObserverPattern}, members register themselves with the {@link DataBus}
|
||||||
|
@ -28,7 +28,7 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<groupId>com.iluwatar</groupId>
|
<groupId>com.iluwatar</groupId>
|
||||||
<artifactId>java-design-patterns</artifactId>
|
<artifactId>java-design-patterns</artifactId>
|
||||||
<version>1.18.0</version>
|
<version>1.19.0</version>
|
||||||
</parent>
|
</parent>
|
||||||
<artifactId>data-mapper</artifactId>
|
<artifactId>data-mapper</artifactId>
|
||||||
<dependencies>
|
<dependencies>
|
||||||
|
@ -41,8 +41,6 @@ public final class Student implements Serializable {
|
|||||||
* @param grade as respective grade of student
|
* @param grade as respective grade of student
|
||||||
*/
|
*/
|
||||||
public Student(final int studentId, final String name, final char grade) {
|
public Student(final int studentId, final String name, final char grade) {
|
||||||
super();
|
|
||||||
|
|
||||||
this.studentId = studentId;
|
this.studentId = studentId;
|
||||||
this.name = name;
|
this.name = name;
|
||||||
this.grade = grade;
|
this.grade = grade;
|
||||||
|
@ -28,7 +28,7 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<groupId>com.iluwatar</groupId>
|
<groupId>com.iluwatar</groupId>
|
||||||
<artifactId>java-design-patterns</artifactId>
|
<artifactId>java-design-patterns</artifactId>
|
||||||
<version>1.18.0</version>
|
<version>1.19.0</version>
|
||||||
</parent>
|
</parent>
|
||||||
<artifactId>data-transfer-object</artifactId>
|
<artifactId>data-transfer-object</artifactId>
|
||||||
<dependencies>
|
<dependencies>
|
||||||
|
@ -36,7 +36,7 @@ Wikipedia says
|
|||||||
|
|
||||||
Let's take the troll example. First of all we have a simple troll implementing the troll interface
|
Let's take the troll example. First of all we have a simple troll implementing the troll interface
|
||||||
|
|
||||||
```
|
```java
|
||||||
public interface Troll {
|
public interface Troll {
|
||||||
void attack();
|
void attack();
|
||||||
int getAttackPower();
|
int getAttackPower();
|
||||||
@ -66,7 +66,7 @@ public class SimpleTroll implements Troll {
|
|||||||
|
|
||||||
Next we want to add club for the troll. We can do it dynamically by using a decorator
|
Next we want to add club for the troll. We can do it dynamically by using a decorator
|
||||||
|
|
||||||
```
|
```java
|
||||||
public class ClubbedTroll implements Troll {
|
public class ClubbedTroll implements Troll {
|
||||||
|
|
||||||
private static final Logger LOGGER = LoggerFactory.getLogger(ClubbedTroll.class);
|
private static final Logger LOGGER = LoggerFactory.getLogger(ClubbedTroll.class);
|
||||||
@ -97,7 +97,7 @@ public class ClubbedTroll implements Troll {
|
|||||||
|
|
||||||
Here's the troll in action
|
Here's the troll in action
|
||||||
|
|
||||||
```
|
```java
|
||||||
// simple troll
|
// simple troll
|
||||||
Troll troll = new SimpleTroll();
|
Troll troll = new SimpleTroll();
|
||||||
troll.attack(); // The troll tries to grab you!
|
troll.attack(); // The troll tries to grab you!
|
||||||
@ -116,6 +116,9 @@ Use Decorator
|
|||||||
* For responsibilities that can be withdrawn
|
* For responsibilities that can be withdrawn
|
||||||
* When extension by subclassing is impractical. Sometimes a large number of independent extensions are possible and would produce an explosion of subclasses to support every combination. Or a class definition may be hidden or otherwise unavailable for subclassing
|
* When extension by subclassing is impractical. Sometimes a large number of independent extensions are possible and would produce an explosion of subclasses to support every combination. Or a class definition may be hidden or otherwise unavailable for subclassing
|
||||||
|
|
||||||
|
## Tutorial
|
||||||
|
* [Decorator Pattern Tutorial](https://www.journaldev.com/1540/decorator-design-pattern-in-java-example)
|
||||||
|
|
||||||
## Real world examples
|
## Real world examples
|
||||||
* [java.io.InputStream](http://docs.oracle.com/javase/8/docs/api/java/io/InputStream.html), [java.io.OutputStream](http://docs.oracle.com/javase/8/docs/api/java/io/OutputStream.html),
|
* [java.io.InputStream](http://docs.oracle.com/javase/8/docs/api/java/io/InputStream.html), [java.io.OutputStream](http://docs.oracle.com/javase/8/docs/api/java/io/OutputStream.html),
|
||||||
[java.io.Reader](http://docs.oracle.com/javase/8/docs/api/java/io/Reader.html) and [java.io.Writer](http://docs.oracle.com/javase/8/docs/api/java/io/Writer.html)
|
[java.io.Reader](http://docs.oracle.com/javase/8/docs/api/java/io/Reader.html) and [java.io.Writer](http://docs.oracle.com/javase/8/docs/api/java/io/Writer.html)
|
||||||
|
@ -29,7 +29,7 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<groupId>com.iluwatar</groupId>
|
<groupId>com.iluwatar</groupId>
|
||||||
<artifactId>java-design-patterns</artifactId>
|
<artifactId>java-design-patterns</artifactId>
|
||||||
<version>1.18.0</version>
|
<version>1.19.0</version>
|
||||||
</parent>
|
</parent>
|
||||||
<artifactId>decorator</artifactId>
|
<artifactId>decorator</artifactId>
|
||||||
<dependencies>
|
<dependencies>
|
||||||
|
@ -30,7 +30,7 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<artifactId>java-design-patterns</artifactId>
|
<artifactId>java-design-patterns</artifactId>
|
||||||
<groupId>com.iluwatar</groupId>
|
<groupId>com.iluwatar</groupId>
|
||||||
<version>1.18.0</version>
|
<version>1.19.0</version>
|
||||||
</parent>
|
</parent>
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
|
||||||
|
@ -29,7 +29,7 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<groupId>com.iluwatar</groupId>
|
<groupId>com.iluwatar</groupId>
|
||||||
<artifactId>java-design-patterns</artifactId>
|
<artifactId>java-design-patterns</artifactId>
|
||||||
<version>1.18.0</version>
|
<version>1.19.0</version>
|
||||||
</parent>
|
</parent>
|
||||||
<artifactId>dependency-injection</artifactId>
|
<artifactId>dependency-injection</artifactId>
|
||||||
<dependencies>
|
<dependencies>
|
||||||
|
@ -27,7 +27,7 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<groupId>com.iluwatar</groupId>
|
<groupId>com.iluwatar</groupId>
|
||||||
<artifactId>java-design-patterns</artifactId>
|
<artifactId>java-design-patterns</artifactId>
|
||||||
<version>1.18.0</version>
|
<version>1.19.0</version>
|
||||||
</parent>
|
</parent>
|
||||||
<artifactId>double-checked-locking</artifactId>
|
<artifactId>double-checked-locking</artifactId>
|
||||||
<dependencies>
|
<dependencies>
|
||||||
|
@ -29,7 +29,7 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<groupId>com.iluwatar</groupId>
|
<groupId>com.iluwatar</groupId>
|
||||||
<artifactId>java-design-patterns</artifactId>
|
<artifactId>java-design-patterns</artifactId>
|
||||||
<version>1.18.0</version>
|
<version>1.19.0</version>
|
||||||
</parent>
|
</parent>
|
||||||
<artifactId>double-dispatch</artifactId>
|
<artifactId>double-dispatch</artifactId>
|
||||||
<dependencies>
|
<dependencies>
|
||||||
|
@ -26,7 +26,7 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<groupId>com.iluwatar</groupId>
|
<groupId>com.iluwatar</groupId>
|
||||||
<artifactId>java-design-patterns</artifactId>
|
<artifactId>java-design-patterns</artifactId>
|
||||||
<version>1.18.0</version>
|
<version>1.19.0</version>
|
||||||
</parent>
|
</parent>
|
||||||
|
|
||||||
<dependencies>
|
<dependencies>
|
||||||
|
@ -26,7 +26,7 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<groupId>com.iluwatar</groupId>
|
<groupId>com.iluwatar</groupId>
|
||||||
<artifactId>java-design-patterns</artifactId>
|
<artifactId>java-design-patterns</artifactId>
|
||||||
<version>1.18.0</version>
|
<version>1.19.0</version>
|
||||||
</parent>
|
</parent>
|
||||||
|
|
||||||
<dependencies>
|
<dependencies>
|
||||||
|
@ -26,7 +26,7 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<groupId>com.iluwatar</groupId>
|
<groupId>com.iluwatar</groupId>
|
||||||
<artifactId>java-design-patterns</artifactId>
|
<artifactId>java-design-patterns</artifactId>
|
||||||
<version>1.18.0</version>
|
<version>1.19.0</version>
|
||||||
</parent>
|
</parent>
|
||||||
|
|
||||||
<dependencies>
|
<dependencies>
|
||||||
|
@ -28,7 +28,7 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<groupId>com.iluwatar</groupId>
|
<groupId>com.iluwatar</groupId>
|
||||||
<artifactId>java-design-patterns</artifactId>
|
<artifactId>java-design-patterns</artifactId>
|
||||||
<version>1.18.0</version>
|
<version>1.19.0</version>
|
||||||
</parent>
|
</parent>
|
||||||
<artifactId>event-aggregator</artifactId>
|
<artifactId>event-aggregator</artifactId>
|
||||||
<dependencies>
|
<dependencies>
|
||||||
|
@ -30,7 +30,6 @@ package com.iluwatar.event.aggregator;
|
|||||||
public class KingsHand extends EventEmitter implements EventObserver {
|
public class KingsHand extends EventEmitter implements EventObserver {
|
||||||
|
|
||||||
public KingsHand() {
|
public KingsHand() {
|
||||||
super();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public KingsHand(EventObserver obs) {
|
public KingsHand(EventObserver obs) {
|
||||||
|
@ -30,7 +30,6 @@ package com.iluwatar.event.aggregator;
|
|||||||
public class LordBaelish extends EventEmitter {
|
public class LordBaelish extends EventEmitter {
|
||||||
|
|
||||||
public LordBaelish() {
|
public LordBaelish() {
|
||||||
super();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public LordBaelish(EventObserver obs) {
|
public LordBaelish(EventObserver obs) {
|
||||||
|
@ -30,7 +30,6 @@ package com.iluwatar.event.aggregator;
|
|||||||
public class LordVarys extends EventEmitter {
|
public class LordVarys extends EventEmitter {
|
||||||
|
|
||||||
public LordVarys() {
|
public LordVarys() {
|
||||||
super();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public LordVarys(EventObserver obs) {
|
public LordVarys(EventObserver obs) {
|
||||||
|
@ -30,7 +30,6 @@ package com.iluwatar.event.aggregator;
|
|||||||
public class Scout extends EventEmitter {
|
public class Scout extends EventEmitter {
|
||||||
|
|
||||||
public Scout() {
|
public Scout() {
|
||||||
super();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public Scout(EventObserver obs) {
|
public Scout(EventObserver obs) {
|
||||||
|
@ -29,7 +29,7 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<groupId>com.iluwatar</groupId>
|
<groupId>com.iluwatar</groupId>
|
||||||
<artifactId>java-design-patterns</artifactId>
|
<artifactId>java-design-patterns</artifactId>
|
||||||
<version>1.18.0</version>
|
<version>1.19.0</version>
|
||||||
</parent>
|
</parent>
|
||||||
<artifactId>event-asynchronous</artifactId>
|
<artifactId>event-asynchronous</artifactId>
|
||||||
<dependencies>
|
<dependencies>
|
||||||
|
@ -31,7 +31,7 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<groupId>com.iluwatar</groupId>
|
<groupId>com.iluwatar</groupId>
|
||||||
<artifactId>java-design-patterns</artifactId>
|
<artifactId>java-design-patterns</artifactId>
|
||||||
<version>1.18.0</version>
|
<version>1.19.0</version>
|
||||||
</parent>
|
</parent>
|
||||||
|
|
||||||
<artifactId>event-driven-architecture</artifactId>
|
<artifactId>event-driven-architecture</artifactId>
|
||||||
|
@ -33,7 +33,7 @@ import com.iluwatar.eda.model.User;
|
|||||||
/**
|
/**
|
||||||
* An event-driven architecture (EDA) is a framework that orchestrates behavior around the
|
* An event-driven architecture (EDA) is a framework that orchestrates behavior around the
|
||||||
* production, detection and consumption of events as well as the responses they evoke. An event is
|
* production, detection and consumption of events as well as the responses they evoke. An event is
|
||||||
* any identifiable occurrence that has significance for system hardware or software. <p/> The
|
* any identifiable occurrence that has significance for system hardware or software. <p> The
|
||||||
* example below uses an {@link EventDispatcher} to link/register {@link Event} objects to their
|
* example below uses an {@link EventDispatcher} to link/register {@link Event} objects to their
|
||||||
* respective handlers once an {@link Event} is dispatched, it's respective handler is invoked and
|
* respective handlers once an {@link Event} is dispatched, it's respective handler is invoked and
|
||||||
* the {@link Event} is handled accordingly.
|
* the {@link Event} is handled accordingly.
|
||||||
|
@ -30,7 +30,7 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<artifactId>java-design-patterns</artifactId>
|
<artifactId>java-design-patterns</artifactId>
|
||||||
<groupId>com.iluwatar</groupId>
|
<groupId>com.iluwatar</groupId>
|
||||||
<version>1.18.0</version>
|
<version>1.19.0</version>
|
||||||
</parent>
|
</parent>
|
||||||
<artifactId>event-queue</artifactId>
|
<artifactId>event-queue</artifactId>
|
||||||
<dependencies>
|
<dependencies>
|
||||||
|
@ -59,7 +59,7 @@ public class Audio {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This method stops the Update Method's thread.
|
* This method check the Update Method's thread is started.
|
||||||
* @return boolean
|
* @return boolean
|
||||||
*/
|
*/
|
||||||
public static synchronized boolean isServiceRunning() {
|
public static synchronized boolean isServiceRunning() {
|
||||||
|
@ -30,7 +30,7 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<artifactId>java-design-patterns</artifactId>
|
<artifactId>java-design-patterns</artifactId>
|
||||||
<groupId>com.iluwatar</groupId>
|
<groupId>com.iluwatar</groupId>
|
||||||
<version>1.18.0</version>
|
<version>1.19.0</version>
|
||||||
</parent>
|
</parent>
|
||||||
<artifactId>event-sourcing</artifactId>
|
<artifactId>event-sourcing</artifactId>
|
||||||
<dependencies>
|
<dependencies>
|
||||||
|
@ -29,7 +29,7 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<groupId>com.iluwatar</groupId>
|
<groupId>com.iluwatar</groupId>
|
||||||
<artifactId>java-design-patterns</artifactId>
|
<artifactId>java-design-patterns</artifactId>
|
||||||
<version>1.18.0</version>
|
<version>1.19.0</version>
|
||||||
</parent>
|
</parent>
|
||||||
<artifactId>execute-around</artifactId>
|
<artifactId>execute-around</artifactId>
|
||||||
<dependencies>
|
<dependencies>
|
||||||
|
@ -29,7 +29,7 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<artifactId>java-design-patterns</artifactId>
|
<artifactId>java-design-patterns</artifactId>
|
||||||
<groupId>com.iluwatar</groupId>
|
<groupId>com.iluwatar</groupId>
|
||||||
<version>1.18.0</version>
|
<version>1.19.0</version>
|
||||||
</parent>
|
</parent>
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
|
||||||
|
@ -32,7 +32,7 @@ Wikipedia says
|
|||||||
|
|
||||||
Taking our goldmine example from above. Here we have the dwarven mine worker hierarchy
|
Taking our goldmine example from above. Here we have the dwarven mine worker hierarchy
|
||||||
|
|
||||||
```
|
```java
|
||||||
public abstract class DwarvenMineWorker {
|
public abstract class DwarvenMineWorker {
|
||||||
|
|
||||||
private static final Logger LOGGER = LoggerFactory.getLogger(DwarvenMineWorker.class);
|
private static final Logger LOGGER = LoggerFactory.getLogger(DwarvenMineWorker.class);
|
||||||
@ -140,7 +140,7 @@ public class DwarvenCartOperator extends DwarvenMineWorker {
|
|||||||
|
|
||||||
To operate all these goldmine workers we have the facade
|
To operate all these goldmine workers we have the facade
|
||||||
|
|
||||||
```
|
```java
|
||||||
public class DwarvenGoldmineFacade {
|
public class DwarvenGoldmineFacade {
|
||||||
|
|
||||||
private final List<DwarvenMineWorker> workers;
|
private final List<DwarvenMineWorker> workers;
|
||||||
@ -175,7 +175,7 @@ public class DwarvenGoldmineFacade {
|
|||||||
|
|
||||||
Now to use the facade
|
Now to use the facade
|
||||||
|
|
||||||
```
|
```java
|
||||||
DwarvenGoldmineFacade facade = new DwarvenGoldmineFacade();
|
DwarvenGoldmineFacade facade = new DwarvenGoldmineFacade();
|
||||||
facade.startNewDay();
|
facade.startNewDay();
|
||||||
// Dwarf gold digger wakes up.
|
// Dwarf gold digger wakes up.
|
||||||
|
@ -29,7 +29,7 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<groupId>com.iluwatar</groupId>
|
<groupId>com.iluwatar</groupId>
|
||||||
<artifactId>java-design-patterns</artifactId>
|
<artifactId>java-design-patterns</artifactId>
|
||||||
<version>1.18.0</version>
|
<version>1.19.0</version>
|
||||||
</parent>
|
</parent>
|
||||||
<artifactId>facade</artifactId>
|
<artifactId>facade</artifactId>
|
||||||
<dependencies>
|
<dependencies>
|
||||||
|
@ -30,7 +30,7 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<groupId>com.iluwatar</groupId>
|
<groupId>com.iluwatar</groupId>
|
||||||
<artifactId>java-design-patterns</artifactId>
|
<artifactId>java-design-patterns</artifactId>
|
||||||
<version>1.18.0</version>
|
<version>1.19.0</version>
|
||||||
</parent>
|
</parent>
|
||||||
<artifactId>factory-kit</artifactId>
|
<artifactId>factory-kit</artifactId>
|
||||||
<dependencies>
|
<dependencies>
|
||||||
|
@ -45,7 +45,7 @@ public class App {
|
|||||||
/**
|
/**
|
||||||
* Program entry point.
|
* Program entry point.
|
||||||
*
|
*
|
||||||
* @param args @param args command line args
|
* @param args command line args
|
||||||
*/
|
*/
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
WeaponFactory factory = WeaponFactory.factory(builder -> {
|
WeaponFactory factory = WeaponFactory.factory(builder -> {
|
||||||
|
@ -35,7 +35,7 @@ Wikipedia says
|
|||||||
|
|
||||||
Taking our blacksmith example above. First of all we have a blacksmith interface and some implementations for it
|
Taking our blacksmith example above. First of all we have a blacksmith interface and some implementations for it
|
||||||
|
|
||||||
```
|
```java
|
||||||
public interface Blacksmith {
|
public interface Blacksmith {
|
||||||
Weapon manufactureWeapon(WeaponType weaponType);
|
Weapon manufactureWeapon(WeaponType weaponType);
|
||||||
}
|
}
|
||||||
@ -55,7 +55,7 @@ public class OrcBlacksmith implements Blacksmith {
|
|||||||
|
|
||||||
Now as the customers come the correct type of blacksmith is summoned and requested weapons are manufactured
|
Now as the customers come the correct type of blacksmith is summoned and requested weapons are manufactured
|
||||||
|
|
||||||
```
|
```java
|
||||||
Blacksmith blacksmith = new ElfBlacksmith();
|
Blacksmith blacksmith = new ElfBlacksmith();
|
||||||
blacksmith.manufactureWeapon(WeaponType.SPEAR);
|
blacksmith.manufactureWeapon(WeaponType.SPEAR);
|
||||||
blacksmith.manufactureWeapon(WeaponType.AXE);
|
blacksmith.manufactureWeapon(WeaponType.AXE);
|
||||||
|
@ -29,7 +29,7 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<groupId>com.iluwatar</groupId>
|
<groupId>com.iluwatar</groupId>
|
||||||
<artifactId>java-design-patterns</artifactId>
|
<artifactId>java-design-patterns</artifactId>
|
||||||
<version>1.18.0</version>
|
<version>1.19.0</version>
|
||||||
</parent>
|
</parent>
|
||||||
<artifactId>factory-method</artifactId>
|
<artifactId>factory-method</artifactId>
|
||||||
<dependencies>
|
<dependencies>
|
||||||
|
@ -30,7 +30,7 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<artifactId>java-design-patterns</artifactId>
|
<artifactId>java-design-patterns</artifactId>
|
||||||
<groupId>com.iluwatar</groupId>
|
<groupId>com.iluwatar</groupId>
|
||||||
<version>1.18.0</version>
|
<version>1.19.0</version>
|
||||||
</parent>
|
</parent>
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
|
||||||
|
@ -67,7 +67,7 @@ public class App {
|
|||||||
* @see UserGroup
|
* @see UserGroup
|
||||||
* @see Service
|
* @see Service
|
||||||
* @see PropertiesFeatureToggleVersion
|
* @see PropertiesFeatureToggleVersion
|
||||||
* @see com.iluwatar.featuretoggle.pattern.tieredversion.TieredFeatureToggleVersion;
|
* @see com.iluwatar.featuretoggle.pattern.tieredversion.TieredFeatureToggleVersion
|
||||||
*/
|
*/
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
|
|
||||||
|
@ -47,7 +47,7 @@ public interface Service {
|
|||||||
/**
|
/**
|
||||||
* Returns if the welcome message to be displayed will be the enhanced version.
|
* Returns if the welcome message to be displayed will be the enhanced version.
|
||||||
*
|
*
|
||||||
* @return Boolean {@value true} if enhanced.
|
* @return Boolean {@code true} if enhanced.
|
||||||
*/
|
*/
|
||||||
boolean isEnhanced();
|
boolean isEnhanced();
|
||||||
|
|
||||||
|
@ -91,7 +91,7 @@ public class PropertiesFeatureToggleVersion implements Service {
|
|||||||
* see the value of the boolean that was set in the constructor
|
* see the value of the boolean that was set in the constructor
|
||||||
* {@link PropertiesFeatureToggleVersion#PropertiesFeatureToggleVersion(Properties)}
|
* {@link PropertiesFeatureToggleVersion#PropertiesFeatureToggleVersion(Properties)}
|
||||||
*
|
*
|
||||||
* @return Boolean value {@value true} if enhanced.
|
* @return Boolean value {@code true} if enhanced.
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public boolean isEnhanced() {
|
public boolean isEnhanced() {
|
||||||
|
@ -65,7 +65,7 @@ public class TieredFeatureToggleVersion implements Service {
|
|||||||
* is driven by the user group. This method is a little redundant. However can be used to show that there is an
|
* is driven by the user group. This method is a little redundant. However can be used to show that there is an
|
||||||
* enhanced version available.
|
* enhanced version available.
|
||||||
*
|
*
|
||||||
* @return Boolean value {@value true} if enhanced.
|
* @return Boolean value {@code true} if enhanced.
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public boolean isEnhanced() {
|
public boolean isEnhanced() {
|
||||||
|
@ -29,7 +29,7 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<artifactId>java-design-patterns</artifactId>
|
<artifactId>java-design-patterns</artifactId>
|
||||||
<groupId>com.iluwatar</groupId>
|
<groupId>com.iluwatar</groupId>
|
||||||
<version>1.18.0</version>
|
<version>1.19.0</version>
|
||||||
</parent>
|
</parent>
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
|
||||||
|
@ -29,7 +29,7 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<groupId>com.iluwatar</groupId>
|
<groupId>com.iluwatar</groupId>
|
||||||
<artifactId>java-design-patterns</artifactId>
|
<artifactId>java-design-patterns</artifactId>
|
||||||
<version>1.18.0</version>
|
<version>1.19.0</version>
|
||||||
</parent>
|
</parent>
|
||||||
<artifactId>flux</artifactId>
|
<artifactId>flux</artifactId>
|
||||||
<dependencies>
|
<dependencies>
|
||||||
|
@ -32,7 +32,7 @@ Wikipedia says
|
|||||||
|
|
||||||
Translating our alchemist shop example from above. First of all we have different potion types
|
Translating our alchemist shop example from above. First of all we have different potion types
|
||||||
|
|
||||||
```
|
```java
|
||||||
public interface Potion {
|
public interface Potion {
|
||||||
void drink();
|
void drink();
|
||||||
}
|
}
|
||||||
@ -64,7 +64,7 @@ public class InvisibilityPotion implements Potion {
|
|||||||
|
|
||||||
Then the actual Flyweight object which is the factory for creating potions
|
Then the actual Flyweight object which is the factory for creating potions
|
||||||
|
|
||||||
```
|
```java
|
||||||
public class PotionFactory {
|
public class PotionFactory {
|
||||||
|
|
||||||
private final Map<PotionType, Potion> potions;
|
private final Map<PotionType, Potion> potions;
|
||||||
@ -100,7 +100,7 @@ public class PotionFactory {
|
|||||||
|
|
||||||
And it can be used as below
|
And it can be used as below
|
||||||
|
|
||||||
```
|
```java
|
||||||
PotionFactory factory = new PotionFactory();
|
PotionFactory factory = new PotionFactory();
|
||||||
factory.createPotion(PotionType.INVISIBILITY).drink(); // You become invisible. (Potion=6566818)
|
factory.createPotion(PotionType.INVISIBILITY).drink(); // You become invisible. (Potion=6566818)
|
||||||
factory.createPotion(PotionType.HEALING).drink(); // You feel healed. (Potion=648129364)
|
factory.createPotion(PotionType.HEALING).drink(); // You feel healed. (Potion=648129364)
|
||||||
|
@ -29,7 +29,7 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<groupId>com.iluwatar</groupId>
|
<groupId>com.iluwatar</groupId>
|
||||||
<artifactId>java-design-patterns</artifactId>
|
<artifactId>java-design-patterns</artifactId>
|
||||||
<version>1.18.0</version>
|
<version>1.19.0</version>
|
||||||
</parent>
|
</parent>
|
||||||
<artifactId>flyweight</artifactId>
|
<artifactId>flyweight</artifactId>
|
||||||
<dependencies>
|
<dependencies>
|
||||||
|
@ -30,7 +30,7 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<groupId>com.iluwatar</groupId>
|
<groupId>com.iluwatar</groupId>
|
||||||
<artifactId>java-design-patterns</artifactId>
|
<artifactId>java-design-patterns</artifactId>
|
||||||
<version>1.18.0</version>
|
<version>1.19.0</version>
|
||||||
</parent>
|
</parent>
|
||||||
<artifactId>front-controller</artifactId>
|
<artifactId>front-controller</artifactId>
|
||||||
<dependencies>
|
<dependencies>
|
||||||
|
@ -30,7 +30,7 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<groupId>com.iluwatar</groupId>
|
<groupId>com.iluwatar</groupId>
|
||||||
<artifactId>java-design-patterns</artifactId>
|
<artifactId>java-design-patterns</artifactId>
|
||||||
<version>1.18.0</version>
|
<version>1.19.0</version>
|
||||||
</parent>
|
</parent>
|
||||||
<packaging>jar</packaging>
|
<packaging>jar</packaging>
|
||||||
<artifactId>guarded-suspension</artifactId>
|
<artifactId>guarded-suspension</artifactId>
|
||||||
|
@ -32,7 +32,7 @@ import java.util.Queue;
|
|||||||
* Guarded Queue is an implementation for Guarded Suspension Pattern
|
* Guarded Queue is an implementation for Guarded Suspension Pattern
|
||||||
* Guarded suspension pattern is used to handle a situation when you want to execute a method
|
* Guarded suspension pattern is used to handle a situation when you want to execute a method
|
||||||
* on an object which is not in a proper state.
|
* on an object which is not in a proper state.
|
||||||
* @see http://java-design-patterns.com/patterns/guarded-suspension/
|
* @see <a href="http://java-design-patterns.com/patterns/guarded-suspension/">http://java-design-patterns.com/patterns/guarded-suspension/</a>
|
||||||
*/
|
*/
|
||||||
public class GuardedQueue {
|
public class GuardedQueue {
|
||||||
private static final Logger LOGGER = LoggerFactory.getLogger(GuardedQueue.class);
|
private static final Logger LOGGER = LoggerFactory.getLogger(GuardedQueue.class);
|
||||||
|
@ -29,7 +29,7 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<groupId>com.iluwatar</groupId>
|
<groupId>com.iluwatar</groupId>
|
||||||
<artifactId>java-design-patterns</artifactId>
|
<artifactId>java-design-patterns</artifactId>
|
||||||
<version>1.18.0</version>
|
<version>1.19.0</version>
|
||||||
</parent>
|
</parent>
|
||||||
<artifactId>half-sync-half-async</artifactId>
|
<artifactId>half-sync-half-async</artifactId>
|
||||||
<dependencies>
|
<dependencies>
|
||||||
|
@ -33,31 +33,31 @@ import java.util.concurrent.LinkedBlockingQueue;
|
|||||||
* {@link AsyncTask} and {@link AsynchronousService}.
|
* {@link AsyncTask} and {@link AsynchronousService}.
|
||||||
*
|
*
|
||||||
* <p>
|
* <p>
|
||||||
* <i>PROBLEM</i> <br/>
|
* <i>PROBLEM</i> <br>
|
||||||
* A concurrent system have a mixture of short duration, mid duration and long duration tasks. Mid
|
* A concurrent system have a mixture of short duration, mid duration and long duration tasks. Mid
|
||||||
* or long duration tasks should be performed asynchronously to meet quality of service
|
* or long duration tasks should be performed asynchronously to meet quality of service
|
||||||
* requirements.
|
* requirements.
|
||||||
*
|
*
|
||||||
* <p>
|
* <p>
|
||||||
* <i>INTENT</i> <br/>
|
* <i>INTENT</i> <br>
|
||||||
* The intent of this pattern is to separate the the synchronous and asynchronous processing in the
|
* The intent of this pattern is to separate the the synchronous and asynchronous processing in the
|
||||||
* concurrent application by introducing two intercommunicating layers - one for sync and one for
|
* concurrent application by introducing two intercommunicating layers - one for sync and one for
|
||||||
* async. This simplifies the programming without unduly affecting the performance.
|
* async. This simplifies the programming without unduly affecting the performance.
|
||||||
*
|
*
|
||||||
* <p>
|
* <p>
|
||||||
* <i>APPLICABILITY</i> <br/>
|
* <i>APPLICABILITY</i> <br>
|
||||||
* UNIX network subsystems - In operating systems network operations are carried out
|
* UNIX network subsystems - In operating systems network operations are carried out
|
||||||
* asynchronously with help of hardware level interrupts.<br/>
|
* asynchronously with help of hardware level interrupts.<br>
|
||||||
* CORBA - At the asynchronous layer one thread is associated with each socket that is connected
|
* CORBA - At the asynchronous layer one thread is associated with each socket that is connected
|
||||||
* to the client. Thread blocks waiting for CORBA requests from the client. On receiving request it
|
* to the client. Thread blocks waiting for CORBA requests from the client. On receiving request it
|
||||||
* is inserted in the queuing layer which is then picked up by synchronous layer which processes the
|
* is inserted in the queuing layer which is then picked up by synchronous layer which processes the
|
||||||
* request and sends response back to the client.<br/>
|
* request and sends response back to the client.<br>
|
||||||
* Android AsyncTask framework - Framework provides a way to execute long running blocking
|
* Android AsyncTask framework - Framework provides a way to execute long running blocking
|
||||||
* calls, such as downloading a file, in background threads so that the UI thread remains free to
|
* calls, such as downloading a file, in background threads so that the UI thread remains free to
|
||||||
* respond to user inputs.<br/>
|
* respond to user inputs.<br>
|
||||||
*
|
*
|
||||||
* <p>
|
* <p>
|
||||||
* <i>IMPLEMENTATION</i> <br/>
|
* <i>IMPLEMENTATION</i> <br>
|
||||||
* The main method creates an asynchronous service which does not block the main thread while the
|
* The main method creates an asynchronous service which does not block the main thread while the
|
||||||
* task is being performed. The main thread continues its work which is similar to Async Method
|
* task is being performed. The main thread continues its work which is similar to Async Method
|
||||||
* Invocation pattern. The difference between them is that there is a queuing layer between
|
* Invocation pattern. The difference between them is that there is a queuing layer between
|
||||||
|
@ -30,7 +30,7 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<groupId>com.iluwatar</groupId>
|
<groupId>com.iluwatar</groupId>
|
||||||
<artifactId>java-design-patterns</artifactId>
|
<artifactId>java-design-patterns</artifactId>
|
||||||
<version>1.18.0</version>
|
<version>1.19.0</version>
|
||||||
</parent>
|
</parent>
|
||||||
<artifactId>hexagonal</artifactId>
|
<artifactId>hexagonal</artifactId>
|
||||||
<dependencies>
|
<dependencies>
|
||||||
|
@ -50,13 +50,13 @@ import com.iluwatar.hexagonal.sampledata.SampleData;
|
|||||||
* from the services it uses.<p>
|
* from the services it uses.<p>
|
||||||
*
|
*
|
||||||
* The primary ports for the application are console interfaces
|
* The primary ports for the application are console interfaces
|
||||||
* {@link ConsoleAdministration} through which the lottery round is
|
* {@link com.iluwatar.hexagonal.administration.ConsoleAdministration} through which the lottery round is
|
||||||
* initiated and run and {@link ConsoleLottery} that allows players to
|
* initiated and run and {@link com.iluwatar.hexagonal.service.ConsoleLottery} that allows players to
|
||||||
* submit lottery tickets for the draw.<p>
|
* submit lottery tickets for the draw.<p>
|
||||||
*
|
*
|
||||||
* The secondary ports that application core uses are {@link WireTransfers}
|
* The secondary ports that application core uses are {@link com.iluwatar.hexagonal.banking.WireTransfers}
|
||||||
* which is a banking service, {@link LotteryEventLog} that delivers
|
* which is a banking service, {@link com.iluwatar.hexagonal.eventlog.LotteryEventLog} that delivers
|
||||||
* eventlog as lottery events occur and {@link LotteryTicketRepository}
|
* eventlog as lottery events occur and {@link com.iluwatar.hexagonal.database.LotteryTicketRepository}
|
||||||
* that is the storage for the lottery tickets.
|
* that is the storage for the lottery tickets.
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
@ -29,7 +29,7 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<groupId>com.iluwatar</groupId>
|
<groupId>com.iluwatar</groupId>
|
||||||
<artifactId>java-design-patterns</artifactId>
|
<artifactId>java-design-patterns</artifactId>
|
||||||
<version>1.18.0</version>
|
<version>1.19.0</version>
|
||||||
</parent>
|
</parent>
|
||||||
<artifactId>intercepting-filter</artifactId>
|
<artifactId>intercepting-filter</artifactId>
|
||||||
<dependencies>
|
<dependencies>
|
||||||
|
@ -29,7 +29,7 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<groupId>com.iluwatar</groupId>
|
<groupId>com.iluwatar</groupId>
|
||||||
<artifactId>java-design-patterns</artifactId>
|
<artifactId>java-design-patterns</artifactId>
|
||||||
<version>1.18.0</version>
|
<version>1.19.0</version>
|
||||||
</parent>
|
</parent>
|
||||||
<artifactId>interpreter</artifactId>
|
<artifactId>interpreter</artifactId>
|
||||||
<dependencies>
|
<dependencies>
|
||||||
|
@ -23,6 +23,7 @@
|
|||||||
package com.iluwatar.interpreter;
|
package com.iluwatar.interpreter;
|
||||||
|
|
||||||
import org.junit.jupiter.api.Disabled;
|
import org.junit.jupiter.api.Disabled;
|
||||||
|
import org.junit.jupiter.api.TestInstance;
|
||||||
import org.junit.jupiter.params.ParameterizedTest;
|
import org.junit.jupiter.params.ParameterizedTest;
|
||||||
import org.junit.jupiter.params.provider.Arguments;
|
import org.junit.jupiter.params.provider.Arguments;
|
||||||
import org.junit.jupiter.params.provider.MethodSource;
|
import org.junit.jupiter.params.provider.MethodSource;
|
||||||
@ -43,6 +44,7 @@ import static org.junit.jupiter.api.Assertions.assertNotNull;
|
|||||||
* @param <E> Type of Expression
|
* @param <E> Type of Expression
|
||||||
* @author Jeroen Meulemeester
|
* @author Jeroen Meulemeester
|
||||||
*/
|
*/
|
||||||
|
@TestInstance(TestInstance.Lifecycle.PER_CLASS)
|
||||||
public abstract class ExpressionTest<E extends Expression> {
|
public abstract class ExpressionTest<E extends Expression> {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -88,6 +90,13 @@ public abstract class ExpressionTest<E extends Expression> {
|
|||||||
this.factory = factory;
|
this.factory = factory;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create a new set of test entries with the expected result
|
||||||
|
*
|
||||||
|
* @return The list of parameters used during this test
|
||||||
|
*/
|
||||||
|
public abstract Stream<Arguments> expressionProvider();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Verify if the expression calculates the correct result when calling {@link E#interpret()}
|
* Verify if the expression calculates the correct result when calling {@link E#interpret()}
|
||||||
*/
|
*/
|
||||||
|
@ -38,7 +38,8 @@ public class MinusExpressionTest extends ExpressionTest<MinusExpression> {
|
|||||||
*
|
*
|
||||||
* @return The list of parameters used during this test
|
* @return The list of parameters used during this test
|
||||||
*/
|
*/
|
||||||
public static Stream<Arguments> expressionProvider() {
|
@Override
|
||||||
|
public Stream<Arguments> expressionProvider() {
|
||||||
return prepareParameters((f, s) -> f - s);
|
return prepareParameters((f, s) -> f - s);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user