Merge branch 'javadoc'

This commit is contained in:
Ilkka Seppala 2015-08-21 23:29:48 +03:00
commit cbab406e47
252 changed files with 3737 additions and 2819 deletions

View File

@ -3,20 +3,28 @@ package com.iluwatar.abstractfactory;
/** /**
* *
* The essence of the Abstract Factory pattern is a factory interface * The essence of the Abstract Factory pattern is a factory interface
* (KingdomFactory) and its implementations (ElfKingdomFactory, * ({@link KingdomFactory}) and its implementations ({@link ElfKingdomFactory},
* OrcKingdomFactory). * {@link OrcKingdomFactory}).
* * <p>
* The example uses both concrete implementations to create a king, a castle and * The example uses both concrete implementations to create a king, a castle and
* an army. * an army.
* *
*/ */
public class App { public class App {
/**
* Program entry point
* @param args command line arguments
*/
public static void main(String[] args) { public static void main(String[] args) {
createKingdom(new ElfKingdomFactory()); createKingdom(new ElfKingdomFactory());
createKingdom(new OrcKingdomFactory()); createKingdom(new OrcKingdomFactory());
} }
/**
* Creates kingdom
* @param factory
*/
public static void createKingdom(KingdomFactory factory) { public static void createKingdom(KingdomFactory factory) {
King king = factory.createKing(); King king = factory.createKing();
Castle castle = factory.createCastle(); Castle castle = factory.createCastle();

View File

@ -1,5 +1,10 @@
package com.iluwatar.abstractfactory; package com.iluwatar.abstractfactory;
/**
*
* Army interface
*
*/
public interface Army { public interface Army {
} }

View File

@ -1,5 +1,10 @@
package com.iluwatar.abstractfactory; package com.iluwatar.abstractfactory;
/**
*
* Castle interface
*
*/
public interface Castle { public interface Castle {
} }

View File

@ -1,5 +1,10 @@
package com.iluwatar.abstractfactory; package com.iluwatar.abstractfactory;
/**
*
* ElfArmy
*
*/
public class ElfArmy implements Army { public class ElfArmy implements Army {
@Override @Override

View File

@ -1,5 +1,10 @@
package com.iluwatar.abstractfactory; package com.iluwatar.abstractfactory;
/**
*
* ElfCastle
*
*/
public class ElfCastle implements Castle { public class ElfCastle implements Castle {
@Override @Override

View File

@ -1,5 +1,10 @@
package com.iluwatar.abstractfactory; package com.iluwatar.abstractfactory;
/**
*
* ElfKing
*
*/
public class ElfKing implements King { public class ElfKing implements King {
@Override @Override

View File

@ -2,7 +2,7 @@ package com.iluwatar.abstractfactory;
/** /**
* *
* Concrete factory. * ElfKingdomFactory concrete factory.
* *
*/ */
public class ElfKingdomFactory implements KingdomFactory { public class ElfKingdomFactory implements KingdomFactory {

View File

@ -1,5 +1,10 @@
package com.iluwatar.abstractfactory; package com.iluwatar.abstractfactory;
/**
*
* King interface
*
*/
public interface King { public interface King {
} }

View File

@ -2,7 +2,7 @@ package com.iluwatar.abstractfactory;
/** /**
* *
* The factory interface. * KingdomFactory factory interface.
* *
*/ */
public interface KingdomFactory { public interface KingdomFactory {

View File

@ -1,5 +1,10 @@
package com.iluwatar.abstractfactory; package com.iluwatar.abstractfactory;
/**
*
* OrcArmy
*
*/
public class OrcArmy implements Army { public class OrcArmy implements Army {
@Override @Override

View File

@ -1,5 +1,10 @@
package com.iluwatar.abstractfactory; package com.iluwatar.abstractfactory;
/**
*
* OrcCastle
*
*/
public class OrcCastle implements Castle { public class OrcCastle implements Castle {
@Override @Override

View File

@ -1,5 +1,10 @@
package com.iluwatar.abstractfactory; package com.iluwatar.abstractfactory;
/**
*
* OrcKing
*
*/
public class OrcKing implements King { public class OrcKing implements King {
@Override @Override

View File

@ -2,7 +2,7 @@ package com.iluwatar.abstractfactory;
/** /**
* *
* Concrete factory. * OrcKingdomFactory concrete factory.
* *
*/ */
public class OrcKingdomFactory implements KingdomFactory { public class OrcKingdomFactory implements KingdomFactory {

View File

@ -3,6 +3,11 @@ import org.junit.Test;
import com.iluwatar.abstractfactory.App; import com.iluwatar.abstractfactory.App;
/**
*
* Application test
*
*/
public class AppTest { public class AppTest {
@Test @Test

View File

@ -6,14 +6,18 @@ package com.iluwatar.adapter;
* the adaptee's interface whereas the object adapter uses composition to * the adaptee's interface whereas the object adapter uses composition to
* contain the adaptee in the adapter object. This example uses the object * contain the adaptee in the adapter object. This example uses the object
* adapter approach. * adapter approach.
* * <p>
* The Adapter (GnomeEngineer) converts the interface of the target class * The Adapter ({@link GnomeEngineer}) converts the interface of the target class
* (GoblinGlider) into a suitable one expected by the client * ({@link GoblinGlider}) into a suitable one expected by the client
* (GnomeEngineeringManager). * ({@link GnomeEngineeringManager}).
* *
*/ */
public class App { public class App {
/**
* Program entry point
* @param args command line args
*/
public static void main(String[] args) { public static void main(String[] args) {
Engineer manager = new GnomeEngineeringManager(); Engineer manager = new GnomeEngineeringManager();
manager.operateDevice(); manager.operateDevice();

View File

@ -2,8 +2,8 @@ package com.iluwatar.adapter;
/** /**
* *
* Adapter class. Adapts the interface of the device (GoblinGlider) into * Adapter class. Adapts the interface of the device ({@link GoblinGlider}) into
* Engineer interface expected by the client (GnomeEngineeringManager). * {@link Engineer} interface expected by the client ({@link GnomeEngineeringManager}).
* *
*/ */
public class GnomeEngineer implements Engineer { public class GnomeEngineer implements Engineer {

View File

@ -2,7 +2,7 @@ package com.iluwatar.adapter;
/** /**
* *
* GnomeEngineering manager uses Engineer to operate devices. * GnomeEngineering manager uses {@link Engineer} to operate devices.
* *
*/ */
public class GnomeEngineeringManager implements Engineer { public class GnomeEngineeringManager implements Engineer {

View File

@ -4,6 +4,11 @@ import org.junit.Test;
import com.iluwatar.adapter.App; import com.iluwatar.adapter.App;
/**
*
* Application test
*
*/
public class AppTest { public class AppTest {
@Test @Test

View File

@ -3,29 +3,24 @@ package com.iluwatar.async.method.invocation;
import java.util.concurrent.Callable; import java.util.concurrent.Callable;
/** /**
* <p>
* This application demonstrates the async method invocation pattern. Key parts of the pattern are * This application demonstrates the async method invocation pattern. Key parts of the pattern are
* <code>AsyncResult</code> which is an intermediate container for an asynchronously evaluated value, * <code>AsyncResult</code> which is an intermediate container for an asynchronously evaluated value,
* <code>AsyncCallback</code> which can be provided to be executed on task completion and * <code>AsyncCallback</code> which can be provided to be executed on task completion and
* <code>AsyncExecutor</code> that manages the execution of the async tasks. * <code>AsyncExecutor</code> that manages the execution of the async tasks.
* </p>
* <p> * <p>
* The main method shows example flow of async invocations. The main thread starts multiple tasks with * The main method shows example flow of async invocations. The main thread starts multiple tasks with
* variable durations and then continues its own work. When the main thread has done it's job it collects * variable durations and then continues its own work. When the main thread has done it's job it collects
* the results of the async tasks. Two of the tasks are handled with callbacks, meaning the callbacks are * the results of the async tasks. Two of the tasks are handled with callbacks, meaning the callbacks are
* executed immediately when the tasks complete. * executed immediately when the tasks complete.
* </p>
* <p> * <p>
* Noteworthy difference of thread usage between the async results and callbacks is that the async results * Noteworthy difference of thread usage between the async results and callbacks is that the async results
* are collected in the main thread but the callbacks are executed within the worker threads. This should be * are collected in the main thread but the callbacks are executed within the worker threads. This should be
* noted when working with thread pools. * noted when working with thread pools.
* </p>
* <p> * <p>
* Java provides its own implementations of async method invocation pattern. FutureTask, CompletableFuture * Java provides its own implementations of async method invocation pattern. FutureTask, CompletableFuture
* and ExecutorService are the real world implementations of this pattern. But due to the nature of parallel * and ExecutorService are the real world implementations of this pattern. But due to the nature of parallel
* programming, the implementations are not trivial. This example does not take all possible scenarios into * programming, the implementations are not trivial. This example does not take all possible scenarios into
* account but rather provides a simple version that helps to understand the pattern. * account but rather provides a simple version that helps to understand the pattern.
* </p>
* *
* @see AsyncResult * @see AsyncResult
* @see AsyncCallback * @see AsyncCallback

View File

@ -2,6 +2,13 @@ package com.iluwatar.async.method.invocation;
import java.util.Optional; import java.util.Optional;
/**
*
* AsyncCallback interface
*
* @param <T>
*
*/
public interface AsyncCallback<T> { public interface AsyncCallback<T> {
/** /**

View File

@ -3,6 +3,11 @@ package com.iluwatar.async.method.invocation;
import java.util.concurrent.Callable; import java.util.concurrent.Callable;
import java.util.concurrent.ExecutionException; import java.util.concurrent.ExecutionException;
/**
*
* AsyncExecutor interface
*
*/
public interface AsyncExecutor { public interface AsyncExecutor {
/** /**

View File

@ -2,6 +2,12 @@ package com.iluwatar.async.method.invocation;
import java.util.concurrent.ExecutionException; import java.util.concurrent.ExecutionException;
/**
*
* AsyncResult interface
*
* @param <T>
*/
public interface AsyncResult<T> { public interface AsyncResult<T> {
/** /**

View File

@ -6,7 +6,9 @@ import java.util.concurrent.ExecutionException;
import java.util.concurrent.atomic.AtomicInteger; import java.util.concurrent.atomic.AtomicInteger;
/** /**
*
* Implementation of async executor that creates a new thread for every task. * Implementation of async executor that creates a new thread for every task.
*
*/ */
public class ThreadAsyncExecutor implements AsyncExecutor { public class ThreadAsyncExecutor implements AsyncExecutor {

View File

@ -2,6 +2,11 @@ package com.iluwatar.async.method.invocation;
import org.junit.Test; import org.junit.Test;
/**
*
* Application test
*
*/
public class AppTest { public class AppTest {
@Test @Test

Binary file not shown.

Before

Width:  |  Height:  |  Size: 48 KiB

After

Width:  |  Height:  |  Size: 52 KiB

View File

@ -1,18 +1,18 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<class-diagram version="1.1.8" icons="true" automaticImage="PNG" always-add-relationships="false" generalizations="true" <class-diagram version="1.1.8" icons="true" automaticImage="PNG" always-add-relationships="false" generalizations="true"
realizations="true" associations="true" dependencies="false" nesting-relationships="true"> realizations="true" associations="true" dependencies="false" nesting-relationships="true">
<class id="1" language="java" name="com.iluwatar.bridge.FlyingMagicWeaponImp" project="bridge" <class id="1" language="java" name="com.iluwatar.bridge.FlyingMagicWeaponImpl" project="bridge"
file="/bridge/src/main/java/com/iluwatar/bridge/FlyingMagicWeaponImp.java" binary="false" corner="BOTTOM_RIGHT"> file="/bridge/src/main/java/com/iluwatar/bridge/FlyingMagicWeaponImpl.java" binary="false" corner="BOTTOM_RIGHT">
<position height="105" width="192" x="193" y="297"/> <position height="-1" width="-1" x="515" y="591"/>
<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="2" language="java" name="com.iluwatar.bridge.SoulEatingMagicWeaponImp" project="bridge" <class id="2" language="java" name="com.iluwatar.bridge.SoulEatingMagicWeaponImpl" project="bridge"
file="/bridge/src/main/java/com/iluwatar/bridge/SoulEatingMagicWeaponImp.java" binary="false" corner="BOTTOM_RIGHT"> file="/bridge/src/main/java/com/iluwatar/bridge/SoulEatingMagicWeaponImpl.java" binary="false" corner="BOTTOM_RIGHT">
<position height="105" width="226" x="425" y="297"/> <position height="-1" width="-1" x="791" y="605"/>
<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"/>
@ -21,25 +21,25 @@
</class> </class>
<class id="3" language="java" name="com.iluwatar.bridge.Stormbringer" project="bridge" <class id="3" language="java" name="com.iluwatar.bridge.Stormbringer" project="bridge"
file="/bridge/src/main/java/com/iluwatar/bridge/Stormbringer.java" binary="false" corner="BOTTOM_RIGHT"> file="/bridge/src/main/java/com/iluwatar/bridge/Stormbringer.java" binary="false" corner="BOTTOM_RIGHT">
<position height="160" width="125" x="425" y="442"/> <position height="-1" width="-1" x="791" y="788"/>
<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="4" language="java" name="com.iluwatar.bridge.MagicWeaponImp" project="bridge" <class id="4" language="java" name="com.iluwatar.bridge.MagicWeaponImpl" project="bridge"
file="/bridge/src/main/java/com/iluwatar/bridge/MagicWeaponImp.java" binary="false" corner="BOTTOM_RIGHT"> file="/bridge/src/main/java/com/iluwatar/bridge/MagicWeaponImpl.java" binary="false" corner="BOTTOM_RIGHT">
<position height="141" width="149" x="221" y="79"/> <position height="-1" width="-1" x="791" y="433"/>
<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="5" language="java" name="com.iluwatar.bridge.BlindingMagicWeaponImp" project="bridge" <class id="5" language="java" name="com.iluwatar.bridge.BlindingMagicWeaponImpl" project="bridge"
file="/bridge/src/main/java/com/iluwatar/bridge/BlindingMagicWeaponImp.java" binary="false" corner="BOTTOM_RIGHT"> file="/bridge/src/main/java/com/iluwatar/bridge/BlindingMagicWeaponImpl.java" binary="false" corner="BOTTOM_RIGHT">
<position height="105" width="208" x="691" y="297"/> <position height="-1" width="-1" x="1105" y="593"/>
<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"/>
@ -48,7 +48,7 @@
</class> </class>
<class id="6" language="java" name="com.iluwatar.bridge.SoulEatingMagicWeapon" project="bridge" <class id="6" language="java" name="com.iluwatar.bridge.SoulEatingMagicWeapon" project="bridge"
file="/bridge/src/main/java/com/iluwatar/bridge/SoulEatingMagicWeapon.java" binary="false" corner="BOTTOM_RIGHT"> file="/bridge/src/main/java/com/iluwatar/bridge/SoulEatingMagicWeapon.java" binary="false" corner="BOTTOM_RIGHT">
<position height="178" width="347" x="410" y="79"/> <position height="-1" width="-1" x="380" y="21"/>
<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"/>
@ -57,7 +57,7 @@
</class> </class>
<class id="7" language="java" name="com.iluwatar.bridge.Excalibur" project="bridge" <class id="7" language="java" name="com.iluwatar.bridge.Excalibur" project="bridge"
file="/bridge/src/main/java/com/iluwatar/bridge/Excalibur.java" binary="false" corner="BOTTOM_RIGHT"> file="/bridge/src/main/java/com/iluwatar/bridge/Excalibur.java" binary="false" corner="BOTTOM_RIGHT">
<position height="160" width="124" x="691" y="442"/> <position height="-1" width="-1" x="1105" y="782"/>
<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"/>
@ -66,7 +66,7 @@
</class> </class>
<class id="8" language="java" name="com.iluwatar.bridge.Mjollnir" project="bridge" <class id="8" language="java" name="com.iluwatar.bridge.Mjollnir" project="bridge"
file="/bridge/src/main/java/com/iluwatar/bridge/Mjollnir.java" binary="false" corner="BOTTOM_RIGHT"> file="/bridge/src/main/java/com/iluwatar/bridge/Mjollnir.java" binary="false" corner="BOTTOM_RIGHT">
<position height="160" width="124" x="193" y="442"/> <position height="-1" width="-1" x="515" y="788"/>
<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"/>
@ -75,7 +75,7 @@
</class> </class>
<class id="9" language="java" name="com.iluwatar.bridge.BlindingMagicWeapon" project="bridge" <class id="9" language="java" name="com.iluwatar.bridge.BlindingMagicWeapon" project="bridge"
file="/bridge/src/main/java/com/iluwatar/bridge/BlindingMagicWeapon.java" binary="false" corner="BOTTOM_RIGHT"> file="/bridge/src/main/java/com/iluwatar/bridge/BlindingMagicWeapon.java" binary="false" corner="BOTTOM_RIGHT">
<position height="178" width="313" x="797" y="79"/> <position height="-1" width="-1" x="791" y="14"/>
<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"/>
@ -84,7 +84,7 @@
</class> </class>
<class id="10" language="java" name="com.iluwatar.bridge.MagicWeapon" project="bridge" <class id="10" language="java" name="com.iluwatar.bridge.MagicWeapon" project="bridge"
file="/bridge/src/main/java/com/iluwatar/bridge/MagicWeapon.java" binary="false" corner="BOTTOM_RIGHT"> file="/bridge/src/main/java/com/iluwatar/bridge/MagicWeapon.java" binary="false" corner="BOTTOM_RIGHT">
<position height="159" width="221" x="644" y="-120"/> <position height="-1" width="-1" x="791" y="237"/>
<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"/>
@ -93,7 +93,7 @@
</class> </class>
<class id="11" language="java" name="com.iluwatar.bridge.FlyingMagicWeapon" project="bridge" <class id="11" language="java" name="com.iluwatar.bridge.FlyingMagicWeapon" project="bridge"
file="/bridge/src/main/java/com/iluwatar/bridge/FlyingMagicWeapon.java" binary="false" corner="BOTTOM_RIGHT"> file="/bridge/src/main/java/com/iluwatar/bridge/FlyingMagicWeapon.java" binary="false" corner="BOTTOM_RIGHT">
<position height="178" width="291" x="1150" y="79"/> <position height="-1" width="-1" x="1144" y="12"/>
<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"/>
@ -101,48 +101,52 @@
</display> </display>
</class> </class>
<generalization id="12"> <generalization id="12">
<end type="SOURCE" refId="11"/> <end type="SOURCE" refId="8"/>
<end type="TARGET" refId="10"/> <end type="TARGET" refId="1"/>
</generalization> </generalization>
<generalization id="13"> <generalization id="13">
<end type="SOURCE" refId="1"/> <end type="SOURCE" refId="1"/>
<end type="TARGET" refId="4"/> <end type="TARGET" refId="4"/>
</generalization> </generalization>
<generalization id="14"> <generalization id="14">
<end type="SOURCE" refId="2"/>
<end type="TARGET" refId="4"/>
</generalization>
<generalization id="15">
<end type="SOURCE" refId="7"/>
<end type="TARGET" refId="5"/>
</generalization>
<generalization id="16">
<end type="SOURCE" refId="6"/>
<end type="TARGET" refId="10"/>
</generalization>
<generalization id="17">
<end type="SOURCE" refId="9"/> <end type="SOURCE" refId="9"/>
<end type="TARGET" refId="10"/> <end type="TARGET" refId="10"/>
</generalization> </generalization>
<generalization id="18"> <generalization id="15">
<end type="SOURCE" refId="3"/> <end type="SOURCE" refId="2"/>
<end type="TARGET" refId="2"/> <end type="TARGET" refId="4"/>
</generalization> </generalization>
<association id="19"> <association id="16">
<end type="SOURCE" refId="10" navigable="false"> <end type="SOURCE" refId="10" navigable="false">
<attribute id="20" name="imp"/> <attribute id="17" name="imp">
<multiplicity id="21" minimum="0" maximum="1"/> <position height="0" width="0" x="478" y="284"/>
</attribute>
<multiplicity id="18" minimum="0" maximum="1">
<position height="0" width="0" x="478" y="284"/>
</multiplicity>
</end> </end>
<end type="TARGET" refId="4" navigable="true"/> <end type="TARGET" refId="4" navigable="true"/>
<display labels="true" multiplicity="true"/> <display labels="true" multiplicity="true"/>
</association> </association>
<generalization id="22"> <generalization id="19">
<end type="SOURCE" refId="5"/> <end type="SOURCE" refId="5"/>
<end type="TARGET" refId="4"/> <end type="TARGET" refId="4"/>
</generalization> </generalization>
<generalization id="20">
<end type="SOURCE" refId="6"/>
<end type="TARGET" refId="10"/>
</generalization>
<generalization id="21">
<end type="SOURCE" refId="7"/>
<end type="TARGET" refId="5"/>
</generalization>
<generalization id="22">
<end type="SOURCE" refId="3"/>
<end type="TARGET" refId="2"/>
</generalization>
<generalization id="23"> <generalization id="23">
<end type="SOURCE" refId="8"/> <end type="SOURCE" refId="11"/>
<end type="TARGET" refId="1"/> <end type="TARGET" refId="10"/>
</generalization> </generalization>
<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">

Binary file not shown.

Before

Width:  |  Height:  |  Size: 85 KiB

View File

@ -11,7 +11,7 @@ tags: Java
vary independently. vary independently.
![alt text](./etc/bridge_1.png "Bridge") ![alt text](./etc/bridge.png "Bridge")
**Applicability:** Use the Bridge pattern when **Applicability:** Use the Bridge pattern when

View File

@ -2,13 +2,17 @@ package com.iluwatar.bridge;
/** /**
* *
* In Bridge pattern both abstraction (MagicWeapon) and implementation * In Bridge pattern both abstraction ({@link MagicWeapon}) and implementation
* (MagicWeaponImp) have their own class hierarchies. The interface of the * ({@link MagicWeaponImpl}) have their own class hierarchies. The interface of the
* implementations can be changed without affecting the clients. * implementations can be changed without affecting the clients.
* *
*/ */
public class App { public class App {
/**
* Program entry point
* @param args command line args
*/
public static void main(String[] args) { public static void main(String[] args) {
BlindingMagicWeapon blindingMagicWeapon = new BlindingMagicWeapon( BlindingMagicWeapon blindingMagicWeapon = new BlindingMagicWeapon(
new Excalibur()); new Excalibur());

View File

@ -1,14 +1,19 @@
package com.iluwatar.bridge; package com.iluwatar.bridge;
/**
*
* BlindingMagicWeapon
*
*/
public class BlindingMagicWeapon extends MagicWeapon { public class BlindingMagicWeapon extends MagicWeapon {
public BlindingMagicWeapon(BlindingMagicWeaponImp imp) { public BlindingMagicWeapon(BlindingMagicWeaponImpl imp) {
super(imp); super(imp);
} }
@Override @Override
public BlindingMagicWeaponImp getImp() { public BlindingMagicWeaponImpl getImp() {
return (BlindingMagicWeaponImp) imp; return (BlindingMagicWeaponImpl) imp;
} }
@Override @Override

View File

@ -1,7 +0,0 @@
package com.iluwatar.bridge;
public abstract class BlindingMagicWeaponImp extends MagicWeaponImp {
public abstract void blindImp();
}

View File

@ -0,0 +1,12 @@
package com.iluwatar.bridge;
/**
*
* BlindingMagicWeaponImpl
*
*/
public abstract class BlindingMagicWeaponImpl extends MagicWeaponImpl {
public abstract void blindImp();
}

View File

@ -1,6 +1,11 @@
package com.iluwatar.bridge; package com.iluwatar.bridge;
public class Excalibur extends BlindingMagicWeaponImp { /**
*
* Excalibur
*
*/
public class Excalibur extends BlindingMagicWeaponImpl {
@Override @Override
public void wieldImp() { public void wieldImp() {

View File

@ -1,13 +1,18 @@
package com.iluwatar.bridge; package com.iluwatar.bridge;
/**
*
* FlyingMagicWeapon
*
*/
public class FlyingMagicWeapon extends MagicWeapon { public class FlyingMagicWeapon extends MagicWeapon {
public FlyingMagicWeapon(FlyingMagicWeaponImp imp) { public FlyingMagicWeapon(FlyingMagicWeaponImpl imp) {
super(imp); super(imp);
} }
public FlyingMagicWeaponImp getImp() { public FlyingMagicWeaponImpl getImp() {
return (FlyingMagicWeaponImp) imp; return (FlyingMagicWeaponImpl) imp;
} }
@Override @Override

View File

@ -1,7 +0,0 @@
package com.iluwatar.bridge;
public abstract class FlyingMagicWeaponImp extends MagicWeaponImp {
public abstract void flyImp();
}

View File

@ -0,0 +1,12 @@
package com.iluwatar.bridge;
/**
*
* FlyingMagicWeaponImpl
*
*/
public abstract class FlyingMagicWeaponImpl extends MagicWeaponImpl {
public abstract void flyImp();
}

View File

@ -2,14 +2,14 @@ package com.iluwatar.bridge;
/** /**
* *
* Abstraction interface. * MagicWeapon
* *
*/ */
public abstract class MagicWeapon { public abstract class MagicWeapon {
protected MagicWeaponImp imp; protected MagicWeaponImpl imp;
public MagicWeapon(MagicWeaponImp imp) { public MagicWeapon(MagicWeaponImpl imp) {
this.imp = imp; this.imp = imp;
} }
@ -19,7 +19,7 @@ public abstract class MagicWeapon {
public abstract void unwield(); public abstract void unwield();
public MagicWeaponImp getImp() { public MagicWeaponImpl getImp() {
return imp; return imp;
} }

View File

@ -2,10 +2,10 @@ package com.iluwatar.bridge;
/** /**
* *
* Implementation interface. * MagicWeaponImpl
* *
*/ */
public abstract class MagicWeaponImp { public abstract class MagicWeaponImpl {
public abstract void wieldImp(); public abstract void wieldImp();

View File

@ -1,6 +1,11 @@
package com.iluwatar.bridge; package com.iluwatar.bridge;
public class Mjollnir extends FlyingMagicWeaponImp { /**
*
* Mjollnir
*
*/
public class Mjollnir extends FlyingMagicWeaponImpl {
@Override @Override
public void wieldImp() { public void wieldImp() {

View File

@ -1,14 +1,19 @@
package com.iluwatar.bridge; package com.iluwatar.bridge;
/**
*
* SoulEatingMagicWeapon
*
*/
public class SoulEatingMagicWeapon extends MagicWeapon { public class SoulEatingMagicWeapon extends MagicWeapon {
public SoulEatingMagicWeapon(SoulEatingMagicWeaponImp imp) { public SoulEatingMagicWeapon(SoulEatingMagicWeaponImpl imp) {
super(imp); super(imp);
} }
@Override @Override
public SoulEatingMagicWeaponImp getImp() { public SoulEatingMagicWeaponImpl getImp() {
return (SoulEatingMagicWeaponImp) imp; return (SoulEatingMagicWeaponImpl) imp;
} }
@Override @Override

View File

@ -1,7 +0,0 @@
package com.iluwatar.bridge;
public abstract class SoulEatingMagicWeaponImp extends MagicWeaponImp {
public abstract void eatSoulImp();
}

View File

@ -0,0 +1,12 @@
package com.iluwatar.bridge;
/**
*
* SoulEatingMagicWeaponImpl
*
*/
public abstract class SoulEatingMagicWeaponImpl extends MagicWeaponImpl {
public abstract void eatSoulImp();
}

View File

@ -1,6 +1,11 @@
package com.iluwatar.bridge; package com.iluwatar.bridge;
public class Stormbringer extends SoulEatingMagicWeaponImp { /**
*
* Stormbringer
*
*/
public class Stormbringer extends SoulEatingMagicWeaponImpl {
@Override @Override
public void wieldImp() { public void wieldImp() {

View File

@ -4,6 +4,11 @@ import org.junit.Test;
import com.iluwatar.bridge.App; import com.iluwatar.bridge.App;
/**
*
* Application test
*
*/
public class AppTest { public class AppTest {
@Test @Test

View File

@ -6,17 +6,21 @@ import com.iluwatar. builder.Hero.HeroBuilder;
* *
* This is the Builder pattern variation as described by Joshua Bloch in * This is the Builder pattern variation as described by Joshua Bloch in
* Effective Java 2nd Edition. * Effective Java 2nd Edition.
* * <p>
* We want to build Hero objects, but its construction is complex because of the * We want to build {@link Hero} objects, but its construction is complex because of the
* many parameters needed. To aid the user we introduce HeroBuilder class. * many parameters needed. To aid the user we introduce {@link HeroBuilder} class.
* HeroBuilder takes the minimum parameters to build Hero object in its * {@link HeroBuilder} takes the minimum parameters to build {@link Hero} object in its
* constructor. After that additional configuration for the Hero object can be * constructor. After that additional configuration for the {@link Hero} object can be
* done using the fluent HeroBuilder interface. When configuration is ready the * done using the fluent {@link HeroBuilder} interface. When configuration is ready the
* build method is called to receive the final Hero object. * build method is called to receive the final {@link Hero} object.
* *
*/ */
public class App { public class App {
/**
* Program entry point
* @param args command line args
*/
public static void main(String[] args) { public static void main(String[] args) {
Hero mage = new HeroBuilder(Profession.MAGE, "Riobard") Hero mage = new HeroBuilder(Profession.MAGE, "Riobard")

View File

@ -1,5 +1,10 @@
package com.iluwatar.builder; package com.iluwatar.builder;
/**
*
* Armor enumeration
*
*/
public enum Armor { public enum Armor {
CLOTHES("clothes"), LEATHER("leather"), CHAIN_MAIL("chain mail"), PLATE_MAIL("plate mail"); CLOTHES("clothes"), LEATHER("leather"), CHAIN_MAIL("chain mail"), PLATE_MAIL("plate mail");

View File

@ -1,5 +1,10 @@
package com.iluwatar.builder; package com.iluwatar.builder;
/**
*
* HairColor enumeration
*
*/
public enum HairColor { public enum HairColor {
WHITE, BLOND, RED, BROWN, BLACK; WHITE, BLOND, RED, BROWN, BLACK;

View File

@ -1,5 +1,10 @@
package com.iluwatar.builder; package com.iluwatar.builder;
/**
*
* HairType enumeration
*
*/
public enum HairType { public enum HairType {
BALD("bald"), SHORT("short"), CURLY("curly"), LONG_STRAIGHT("long straight"), LONG_CURLY("long curly"); BALD("bald"), SHORT("short"), CURLY("curly"), LONG_STRAIGHT("long straight"), LONG_CURLY("long curly");

View File

@ -2,7 +2,7 @@ package com.iluwatar.builder;
/** /**
* *
* The class with many parameters. * Hero, the class with many parameters.
* *
*/ */
public class Hero { public class Hero {

View File

@ -1,5 +1,10 @@
package com.iluwatar.builder; package com.iluwatar.builder;
/**
*
* Profession enumeration
*
*/
public enum Profession { public enum Profession {
WARRIOR, THIEF, MAGE, PRIEST; WARRIOR, THIEF, MAGE, PRIEST;

View File

@ -1,5 +1,10 @@
package com.iluwatar.builder; package com.iluwatar.builder;
/**
*
* Weapon enumeration
*
*/
public enum Weapon { public enum Weapon {
DAGGER, SWORD, AXE, WARHAMMER, BOW; DAGGER, SWORD, AXE, WARHAMMER, BOW;

View File

@ -4,6 +4,11 @@ import org.junit.Test;
import com.iluwatar. builder.App; import com.iluwatar. builder.App;
/**
*
* Application test
*
*/
public class AppTest { public class AppTest {
@Test @Test

View File

@ -2,21 +2,25 @@ package com.iluwatar.business.delegate;
/** /**
* *
* The Business Delegate pattern adds an abstraction layer between presentation and business tiers. * The Business Delegate pattern adds an abstraction layer between the presentation and business tiers.
* By using the pattern we gain loose coupling between the tiers. The Business Delegate encapsulates * By using the pattern we gain loose coupling between the tiers. The Business Delegate encapsulates
* knowledge about how to locate, connect to, and interact with the business objects that make up * knowledge about how to locate, connect to, and interact with the business objects that make up
* the application. * the application.
* * <p>
* Some of the services the Business Delegate uses are instantiated directly, and some can be retrieved * Some of the services the Business Delegate uses are instantiated directly, and some can be retrieved
* through service lookups. The Business Delegate itself may contain business logic too potentially tying * through service lookups. The Business Delegate itself may contain business logic too potentially tying
* together multiple service calls, exception handling, retrying etc. * together multiple service calls, exception handling, retrying etc.
* * <p>
* In this example the client (Client) utilizes a business delegate (BusinessDelegate) to execute a task. * In this example the client ({@link Client}) utilizes a business delegate ({@link BusinessDelegate}) to execute a task.
* The Business Delegate then selects the appropriate service and makes the service call. * The Business Delegate then selects the appropriate service and makes the service call.
* *
*/ */
public class App { public class App {
/**
* Program entry point
* @param args command line args
*/
public static void main(String[] args) { public static void main(String[] args) {
BusinessDelegate businessDelegate = new BusinessDelegate(); BusinessDelegate businessDelegate = new BusinessDelegate();

View File

@ -2,7 +2,7 @@ package com.iluwatar.business.delegate;
/** /**
* *
* BusinessDelegate separates presentation and business tiers * BusinessDelegate separates the presentation and business tiers
* *
*/ */
public class BusinessDelegate { public class BusinessDelegate {

View File

@ -4,6 +4,11 @@ import org.junit.Test;
import com.iluwatar.business.delegate.App; import com.iluwatar.business.delegate.App;
/**
*
* Application test
*
*/
public class AppTest { public class AppTest {
@Test @Test

View File

@ -1,8 +1,10 @@
package com.iluwatar.callback; package com.iluwatar.callback;
/** /**
* Callback pattern is more native for functional languages where function is treated as first-class citizen. *
* Prior to Java8 can be simulated using simple (alike command) interfaces. * Callback pattern is more native for functional languages where functions are treated as first-class citizens.
* Prior to Java 8 callbacks can be simulated using simple (alike command) interfaces.
*
*/ */
public class App { public class App {

View File

@ -1,7 +1,9 @@
package com.iluwatar.callback; package com.iluwatar.callback;
/** /**
*
* Callback interface * Callback interface
*
*/ */
public interface Callback { public interface Callback {

View File

@ -1,7 +1,9 @@
package com.iluwatar.callback; package com.iluwatar.callback;
/** /**
*
* Implementation of task that need to be executed * Implementation of task that need to be executed
*
*/ */
public class SimpleTask extends Task { public class SimpleTask extends Task {

View File

@ -1,7 +1,9 @@
package com.iluwatar.callback; package com.iluwatar.callback;
/** /**
*
* Template-method class for callback hook execution * Template-method class for callback hook execution
*
*/ */
public abstract class Task { public abstract class Task {

View File

@ -4,6 +4,11 @@ import org.junit.Test;
import com.iluwatar.callback.App; import com.iluwatar.callback.App;
/**
*
* Application test
*
*/
public class AppTest { public class AppTest {
@Test @Test

View File

@ -2,14 +2,18 @@ package com.iluwatar.chain;
/** /**
* *
* Chain of Responsibility organizes request handlers (RequestHandler) into a * Chain of Responsibility organizes request handlers ({@link RequestHandler}) into a
* chain where each handler has a chance to act on the request on its turn. In * chain where each handler has a chance to act on the request on its turn. In
* this example the king (OrcKing) makes requests and the military orcs * this example the king ({@link OrcKing}) makes requests and the military orcs
* (OrcCommander, OrcOfficer, OrcSoldier) form the handler chain. * ({@link OrcCommander}, {@link OrcOfficer}, {@link OrcSoldier}) form the handler chain.
* *
*/ */
public class App { public class App {
/**
* Program entry point
* @param args command line args
*/
public static void main(String[] args) { public static void main(String[] args) {
OrcKing king = new OrcKing(); OrcKing king = new OrcKing();

View File

@ -1,5 +1,10 @@
package com.iluwatar.chain; package com.iluwatar.chain;
/**
*
* OrcCommander
*
*/
public class OrcCommander extends RequestHandler { public class OrcCommander extends RequestHandler {
public OrcCommander(RequestHandler handler) { public OrcCommander(RequestHandler handler) {

View File

@ -2,7 +2,7 @@ package com.iluwatar.chain;
/** /**
* *
* Makes requests that are handled by the chain. * OrcKing makes requests that are handled by the chain.
* *
*/ */
public class OrcKing { public class OrcKing {

View File

@ -1,5 +1,10 @@
package com.iluwatar.chain; package com.iluwatar.chain;
/**
*
* OrcOfficer
*
*/
public class OrcOfficer extends RequestHandler { public class OrcOfficer extends RequestHandler {
public OrcOfficer(RequestHandler handler) { public OrcOfficer(RequestHandler handler) {

View File

@ -1,5 +1,10 @@
package com.iluwatar.chain; package com.iluwatar.chain;
/**
*
* OrcSoldier
*
*/
public class OrcSoldier extends RequestHandler { public class OrcSoldier extends RequestHandler {
public OrcSoldier(RequestHandler handler) { public OrcSoldier(RequestHandler handler) {

View File

@ -1,5 +1,10 @@
package com.iluwatar.chain; package com.iluwatar.chain;
/**
*
* Request
*
*/
public class Request { public class Request {
private String requestDescription; private String requestDescription;

View File

@ -1,5 +1,10 @@
package com.iluwatar.chain; package com.iluwatar.chain;
/**
*
* RequestHandler
*
*/
public abstract class RequestHandler { public abstract class RequestHandler {
private RequestHandler next; private RequestHandler next;

View File

@ -1,5 +1,10 @@
package com.iluwatar.chain; package com.iluwatar.chain;
/**
*
* RequestType enumeration
*
*/
public enum RequestType { public enum RequestType {
DEFEND_CASTLE, TORTURE_PRISONER, COLLECT_TAX DEFEND_CASTLE, TORTURE_PRISONER, COLLECT_TAX

View File

@ -4,6 +4,11 @@ import org.junit.Test;
import com.iluwatar.chain.App; import com.iluwatar.chain.App;
/**
*
* Application test
*
*/
public class AppTest { public class AppTest {
@Test @Test

View File

@ -3,15 +3,15 @@ package com.iluwatar.command;
/** /**
* *
* In Command pattern actions are objects that can be executed and undone. * In Command pattern actions are objects that can be executed and undone.
* * <p>
* Four terms always associated with the command pattern are command, receiver, invoker and client. A command * Four terms always associated with the command pattern are command, receiver, invoker and client. A command
* object (spell) knows about receiver (target) and invokes a method of the receiver. Values for parameters of * object (spell) knows about the receiver (target) and invokes a method of the receiver. Values for parameters of
* the receiver method are stored in the command. The receiver then does the work. An invoker object (wizard) * the receiver method are stored in the command. The receiver then does the work. An invoker object (wizard)
* knows how to execute a command, and optionally does bookkeeping about the command execution. The invoker * knows how to execute a command, and optionally does bookkeeping about the command execution. The invoker
* does not know anything about a concrete command, it knows only about command interface. Both an invoker object * does not know anything about a concrete command, it knows only about command interface. Both an invoker object
* and several command objects are held by a client object (app). The client decides which commands to execute at * and several command objects are held by a client object (app). The client decides which commands to execute at
* which points. To execute a command, it passes the command object to the invoker object. * which points. To execute a command, it passes the command object to the invoker object.
* * <p>
* In other words, in this example the wizard casts spells on the goblin. The wizard keeps track of the previous * In other words, in this example the wizard casts spells on the goblin. The wizard keeps track of the previous
* spells cast, so it is easy to undo them. In addition, the wizard keeps track of the spells undone, so they * spells cast, so it is easy to undo them. In addition, the wizard keeps track of the spells undone, so they
* can be redone. * can be redone.
@ -20,6 +20,10 @@ package com.iluwatar.command;
*/ */
public class App { public class App {
/**
* Program entry point
* @param args command line args
*/
public static void main(String[] args) { public static void main(String[] args) {
Wizard wizard = new Wizard(); Wizard wizard = new Wizard();
Goblin goblin = new Goblin(); Goblin goblin = new Goblin();

View File

@ -4,6 +4,11 @@ import org.junit.Test;
import com.iluwatar.command.App; import com.iluwatar.command.App;
/**
*
* Application test
*
*/
public class AppTest { public class AppTest {
@Test @Test

View File

@ -3,12 +3,16 @@ package com.iluwatar.composite;
/** /**
* *
* With Composite we can treat tree hierarchies of objects with uniform * With Composite we can treat tree hierarchies of objects with uniform
* interface (LetterComposite). In this example we have sentences composed of * interface ({@link LetterComposite}). In this example we have sentences composed of
* words composed of letters. * words composed of letters.
* *
*/ */
public class App { public class App {
/**
* Program entry point
* @param args command line args
*/
public static void main(String[] args) { public static void main(String[] args) {
System.out.println("Message from the orcs: "); System.out.println("Message from the orcs: ");

View File

@ -1,5 +1,10 @@
package com.iluwatar.composite; package com.iluwatar.composite;
/**
*
* Letter
*
*/
public class Letter extends LetterComposite { public class Letter extends LetterComposite {
private char c; private char c;

View File

@ -4,6 +4,11 @@ import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.List; import java.util.List;
/**
*
* Messenger
*
*/
public class Messenger { public class Messenger {
LetterComposite messageFromOrcs() { LetterComposite messageFromOrcs() {

View File

@ -2,6 +2,11 @@ package com.iluwatar.composite;
import java.util.List; import java.util.List;
/**
*
* Sentence
*
*/
public class Sentence extends LetterComposite { public class Sentence extends LetterComposite {
public Sentence(List<Word> words) { public Sentence(List<Word> words) {

View File

@ -2,6 +2,11 @@ package com.iluwatar.composite;
import java.util.List; import java.util.List;
/**
*
* Word
*
*/
public class Word extends LetterComposite { public class Word extends LetterComposite {
public Word(List<Letter> letters) { public Word(List<Letter> letters) {

View File

@ -4,6 +4,11 @@ import org.junit.Test;
import com.iluwatar.composite.App; import com.iluwatar.composite.App;
/**
*
* Application test
*
*/
public class AppTest { public class AppTest {
@Test @Test

View File

@ -7,9 +7,14 @@ import java.util.List;
* *
* With the DAO pattern, we can use various method calls to retrieve/add/delete/update data without directly * With the DAO pattern, we can use various method calls to retrieve/add/delete/update data without directly
* interacting with the data. The below example demonstrates basic operations(CRUD): select, add, update, and delete. * interacting with the data. The below example demonstrates basic operations(CRUD): select, add, update, and delete.
*
*/ */
public class App { public class App {
/**
* Program entry point
* @param args command line args
*/
public static void main(String[] args) { public static void main(String[] args) {
CustomerDaoImpl customerDao = new CustomerDaoImpl(generateSampleCustomers()); CustomerDaoImpl customerDao = new CustomerDaoImpl(generateSampleCustomers());
@ -33,6 +38,10 @@ public class App {
System.out.println("customerDao.getAllCustomers(): " + customerDao.getAllCustomers()); System.out.println("customerDao.getAllCustomers(): " + customerDao.getAllCustomers());
} }
/**
* Generate customers
* @return list of customers
*/
public static List<Customer> generateSampleCustomers() { public static List<Customer> generateSampleCustomers() {
Customer customer1 = new Customer(1, "Adam", "Adamson"); Customer customer1 = new Customer(1, "Adam", "Adamson");
Customer customer2 = new Customer(2, "Bob", "Bobson"); Customer customer2 = new Customer(2, "Bob", "Bobson");

View File

@ -1,6 +1,12 @@
package com.iluwatar.dao; package com.iluwatar.dao;
/**
*
* Customer
*
*/
public class Customer { public class Customer {
private int id; private int id;
private String firstName; private String firstName;
private String lastName; private String lastName;

View File

@ -2,7 +2,13 @@ package com.iluwatar.dao;
import java.util.List; import java.util.List;
/**
*
* CustomerDao
*
*/
public interface CustomerDao { public interface CustomerDao {
public List<Customer> getAllCustomers(); public List<Customer> getAllCustomers();
public Customer getCusterById(int id); public Customer getCusterById(int id);
public void addCustomer(Customer customer); public void addCustomer(Customer customer);

View File

@ -3,11 +3,13 @@ package com.iluwatar.dao;
import java.util.List; import java.util.List;
/** /**
*
* The data access object (DAO) is an object that provides an abstract interface to some type of database or other persistence mechanism. * The data access object (DAO) is an object that provides an abstract interface to some type of database or other persistence mechanism.
* By mapping application calls to the persistence layer, DAO provide some specific data operations without exposing details of the database. * By mapping application calls to the persistence layer, DAO provide some specific data operations without exposing details of the database.
* This isolation supports the Single responsibility principle. It separates what data accesses the application needs, in terms of * This isolation supports the Single responsibility principle. It separates what data accesses the application needs, in terms of
* domain-specific objects and data types (the public interface of the DAO), from how these needs can be satisfied with a specific DBMS, * domain-specific objects and data types (the public interface of the DAO), from how these needs can be satisfied with a specific DBMS,
* database schema, etc. * database schema, etc.
*
*/ */
public class CustomerDaoImpl implements CustomerDao { public class CustomerDaoImpl implements CustomerDao {

View File

@ -4,6 +4,11 @@ import org.junit.Test;
import com.iluwatar.dao.App; import com.iluwatar.dao.App;
/**
*
* Application test
*
*/
public class AppTest { public class AppTest {
@Test @Test

View File

@ -2,16 +2,20 @@ package com.iluwatar.decorator;
/** /**
* *
* Decorator pattern is more flexible alternative to subclassing. The decorator * Decorator pattern is a more flexible alternative to subclassing. The decorator
* class implements the same interface as the target and uses composition to * class implements the same interface as the target and uses composition to
* "decorate" calls to the target. * "decorate" calls to the target.
* * <p>
* Using decorator pattern it is possible to change class behavior during * Using decorator pattern it is possible to change class behavior during
* runtime, as the example shows. * runtime, as the example shows.
* *
*/ */
public class App { public class App {
/**
* Program entry point
* @param args command line args
*/
public static void main(String[] args) { public static void main(String[] args) {
// simple troll // simple troll

View File

@ -1,10 +1,10 @@
package com.iluwatar.decorator; package com.iluwatar.decorator;
/** /**
* SmartTroll is a decorator for Hostile objects. * SmartTroll is a decorator for {@link Hostile} objects.
* The calls to the Hostile interface are intercepted * The calls to the {@link Hostile} interface are intercepted
* and decorated. Finally the calls are delegated * and decorated. Finally the calls are delegated
* to the decorated Hostile object. * to the decorated {@link Hostile} object.
* *
*/ */
public class SmartTroll implements Hostile { public class SmartTroll implements Hostile {

View File

@ -2,7 +2,7 @@ package com.iluwatar.decorator;
/** /**
* *
* Troll implements Hostile interface directly. * Troll implements {@link Hostile} interface directly.
* *
*/ */
public class Troll implements Hostile { public class Troll implements Hostile {

View File

@ -4,6 +4,11 @@ import org.junit.Test;
import com.iluwatar.decorator.App; import com.iluwatar.decorator.App;
/**
*
* Application test
*
*/
public class AppTest { public class AppTest {
@Test @Test

View File

@ -9,23 +9,27 @@ import com.google.inject.Injector;
* implements so called inversion of control principle. Inversion of control has two specific rules: * implements so called inversion of control principle. Inversion of control has two specific rules:
* - High-level modules should not depend on low-level modules. Both should depend on abstractions. * - High-level modules should not depend on low-level modules. Both should depend on abstractions.
* - Abstractions should not depend on details. Details should depend on abstractions. * - Abstractions should not depend on details. Details should depend on abstractions.
* * <p>
* In this example we show you three different wizards. The first one (SimpleWizard) is a naive * In this example we show you three different wizards. The first one ({@link SimpleWizard}) is a naive
* implementation violating the inversion of control principle. It depends directly on a concrete * implementation violating the inversion of control principle. It depends directly on a concrete
* implementation which cannot be changed. * implementation which cannot be changed.
* * <p>
* The second wizard (AdvancedWizard) is more flexible. It does not depend on any concrete implementation * The second wizard ({@link AdvancedWizard}) is more flexible. It does not depend on any concrete implementation
* but abstraction. It utilizes Dependency Injection pattern allowing its Tobacco dependency to be * but abstraction. It utilizes Dependency Injection pattern allowing its {@link Tobacco} dependency to be
* injected through its constructor. This way, handling the dependency is no longer the wizard's * injected through its constructor. This way, handling the dependency is no longer the wizard's
* responsibility. It is resolved outside the wizard class. * responsibility. It is resolved outside the wizard class.
* * <p>
* The third example takes the pattern a step further. It uses Guice framework for Dependency Injection. * The third example takes the pattern a step further. It uses Guice framework for Dependency Injection.
* TobaccoModule binds a concrete implementation to abstraction. Injector is then used to create * {@link TobaccoModule} binds a concrete implementation to abstraction. Injector is then used to create
* GuiceWizard object with correct dependencies. * {@link GuiceWizard} object with correct dependencies.
* *
*/ */
public class App { public class App {
/**
* Program entry point
* @param args command line args
*/
public static void main( String[] args ) { public static void main( String[] args ) {
SimpleWizard simpleWizard = new SimpleWizard(); SimpleWizard simpleWizard = new SimpleWizard();
simpleWizard.smoke(); simpleWizard.smoke();

View File

@ -2,7 +2,7 @@ package com.iluwatar.dependency.injection;
/** /**
* *
* OldTobyTobacco concrete Tobacco implementation * OldTobyTobacco concrete {@link Tobacco} implementation
* *
*/ */
public class OldTobyTobacco extends Tobacco { public class OldTobyTobacco extends Tobacco {

View File

@ -2,7 +2,7 @@ package com.iluwatar.dependency.injection;
/** /**
* *
* RivendellTobacco concrete Tobacco implementation * RivendellTobacco concrete {@link Tobacco} implementation
* *
*/ */
public class RivendellTobacco extends Tobacco { public class RivendellTobacco extends Tobacco {

View File

@ -2,7 +2,7 @@ package com.iluwatar.dependency.injection;
/** /**
* *
* SecondBreakfastTobacco concrete Tobacco implementation * SecondBreakfastTobacco concrete {@link Tobacco} implementation
* *
*/ */
public class SecondBreakfastTobacco extends Tobacco { public class SecondBreakfastTobacco extends Tobacco {

View File

@ -4,7 +4,7 @@ import com.google.inject.AbstractModule;
/** /**
* *
* Guice module for binding certain concrete Tobacco implementation. * Guice module for binding certain concrete {@link Tobacco} implementation.
* *
*/ */
public class TobaccoModule extends AbstractModule { public class TobaccoModule extends AbstractModule {

View File

@ -4,6 +4,11 @@ import org.junit.Test;
import com.iluwatar.dependency.injection.App; import com.iluwatar.dependency.injection.App;
/**
*
* Application test
*
*/
public class AppTest { public class AppTest {
@Test @Test

View File

@ -5,13 +5,18 @@ import java.util.concurrent.Executors;
/** /**
* *
* In Inventory we store the items with a given size. However, we do not store * In {@link Inventory} we store the items with a given size. However, we do not store
* more items than the inventory size. To address concurrent access problems we * more items than the inventory size. To address concurrent access problems we
* use double checked locking to add item to inventory. In this method, the * use double checked locking to add item to inventory. In this method, the
* thread which gets the lock first adds the item. * thread which gets the lock first adds the item.
*
*/ */
public class App { public class App {
/**
* Program entry point
* @param args command line args
*/
public static void main(String[] args) { public static void main(String[] args) {
final Inventory inventory = new Inventory(1000); final Inventory inventory = new Inventory(1000);
ExecutorService executorService = Executors.newFixedThreadPool(3); ExecutorService executorService = Executors.newFixedThreadPool(3);

View File

@ -5,6 +5,11 @@ import java.util.List;
import java.util.concurrent.locks.Lock; import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock; import java.util.concurrent.locks.ReentrantLock;
/**
*
* Inventory
*
*/
public class Inventory { public class Inventory {
private int inventorySize; private int inventorySize;

View File

@ -1,6 +1,12 @@
package com.iluwatar.doublechecked.locking; package com.iluwatar.doublechecked.locking;
/**
*
* Item
*
*/
public class Item { public class Item {
String name;
int level; private String name;
private int level;
} }

View File

@ -4,6 +4,11 @@ import org.junit.Test;
import com.iluwatar.doublechecked.locking.App; import com.iluwatar.doublechecked.locking.App;
/**
*
* Application test
*
*/
public class AppTest { public class AppTest {
@Test @Test

View File

@ -8,23 +8,27 @@ import java.util.List;
* When a message with a parameter is sent to an object, the resultant behaviour is defined by the * When a message with a parameter is sent to an object, the resultant behaviour is defined by the
* implementation of that method in the receiver. Sometimes the behaviour must also be determined * implementation of that method in the receiver. Sometimes the behaviour must also be determined
* by the type of the parameter. * by the type of the parameter.
* * <p>
* One way to implement this would be to create multiple instanceof-checks for the methods parameter. * One way to implement this would be to create multiple instanceof-checks for the methods parameter.
* However, this creates a maintenance issue. When new types are added we would also need to change * However, this creates a maintenance issue. When new types are added we would also need to change
* the method's implementation and add a new instanceof-check. This violates the single responsibility * the method's implementation and add a new instanceof-check. This violates the single responsibility
* principle - a class should have only one reason to change. * principle - a class should have only one reason to change.
* * <p>
* Instead of the instanceof-checks a better way is to make another virtual call on the parameter * Instead of the instanceof-checks a better way is to make another virtual call on the parameter
* object. This way new functionality can be easily added without the need to modify existing * object. This way new functionality can be easily added without the need to modify existing
* implementation (open-closed principle). * implementation (open-closed principle).
* * <p>
* In this example we have hierarchy of objects (GameObject) that can collide to each other. Each * In this example we have hierarchy of objects ({@link GameObject}) that can collide to each other. Each
* object has its own coordinates which are checked against the other objects' coordinates. If * object has its own coordinates which are checked against the other objects' coordinates. If
* there is an overlap, then the objects collide utilizing the Double Dispatch pattern. * there is an overlap, then the objects collide utilizing the Double Dispatch pattern.
* *
*/ */
public class App { public class App {
/**
* Program entry point
* @param args command line args
*/
public static void main( String[] args ) { public static void main( String[] args ) {
// initialize game objects and print their status // initialize game objects and print their status
List<GameObject> objects = new ArrayList<>(); List<GameObject> objects = new ArrayList<>();

View File

@ -4,6 +4,11 @@ import org.junit.Test;
import com.iluwatar.doubledispatch.App; import com.iluwatar.doubledispatch.App;
/**
*
* Application test
*
*/
public class AppTest { public class AppTest {
@Test @Test

View File

@ -7,14 +7,18 @@ import java.util.List;
* *
* The Event Aggregator pattern channels events from multiple objects * The Event Aggregator pattern channels events from multiple objects
* into a single object to simplify registration for clients. * into a single object to simplify registration for clients.
* * <p>
* In the example LordBaelish, LordVarys and Scout deliver events to * In the example {@link LordBaelish}, {@link LordVarys} and {@link Scout} deliver events to
* KingsHand. KingsHand, the event aggregator, then delivers the events * {@link KingsHand}. {@link KingsHand}, the event aggregator, then delivers the events
* to KingJoffrey. * to {@link KingJoffrey}.
* *
*/ */
public class App { public class App {
/**
* Program entry point
* @param args command line args
*/
public static void main(String[] args) { public static void main(String[] args) {
KingJoffrey kingJoffrey = new KingJoffrey(); KingJoffrey kingJoffrey = new KingJoffrey();

View File

@ -2,7 +2,7 @@ package com.iluwatar.event.aggregator;
/** /**
* *
* KingJoffrey observes events from KingsHand. * KingJoffrey observes events from {@link KingsHand}.
* *
*/ */
public class KingJoffrey implements EventObserver { public class KingJoffrey implements EventObserver {

Some files were not shown because too many files have changed in this diff Show More