diff --git a/delegation/src/main/java/com/iluwatar/delegation/simple/App.java b/delegation/src/main/java/com/iluwatar/delegation/simple/App.java index af734bb41..b568c836f 100644 --- a/delegation/src/main/java/com/iluwatar/delegation/simple/App.java +++ b/delegation/src/main/java/com/iluwatar/delegation/simple/App.java @@ -28,23 +28,25 @@ import com.iluwatar.delegation.simple.printers.EpsonPrinter; import com.iluwatar.delegation.simple.printers.HpPrinter; /** - * The delegate pattern provides a mechanism to abstract away the implementation and control of the desired action. - * The class being called in this case {@link PrinterController} is not responsible for the actual desired action, - * but is actually delegated to a helper class either {@link CanonPrinter}, {@link EpsonPrinter} or {@link HpPrinter}. - * The consumer does not have or require knowledge of the actual class carrying out the action, only the - * container on which they are calling. + * The delegate pattern provides a mechanism to abstract away the implementation and control of the + * desired action. The class being called in this case {@link PrinterController} is not responsible + * for the actual desired action, but is actually delegated to a helper class either {@link + * CanonPrinter}, {@link EpsonPrinter} or {@link HpPrinter}. The consumer does not have or require + * knowledge of the actual class carrying out the action, only the container on which they are + * calling. * - * In this example the delegates are {@link EpsonPrinter}, {@link HpPrinter} and {@link CanonPrinter} they all implement - * {@link Printer}. The {@link PrinterController} class also implements {@link Printer}. However neither provide the - * functionality of {@link Printer} by printing to the screen, they actually call upon the instance of {@link Printer} - * that they were instantiated with. Therefore delegating the behaviour to another class. + *
In this example the delegates are {@link EpsonPrinter}, {@link HpPrinter} and {@link + * CanonPrinter} they all implement {@link Printer}. The {@link PrinterController} class also + * implements {@link Printer}. However neither provide the functionality of {@link Printer} by + * printing to the screen, they actually call upon the instance of {@link Printer} that they were + * instantiated with. Therefore delegating the behaviour to another class. */ public class App { private static final String MESSAGE_TO_PRINT = "hello world"; /** - * Program entry point + * Program entry point. * * @param args command line args */ diff --git a/delegation/src/main/java/com/iluwatar/delegation/simple/Printer.java b/delegation/src/main/java/com/iluwatar/delegation/simple/Printer.java index bc6f50879..f3f434adb 100644 --- a/delegation/src/main/java/com/iluwatar/delegation/simple/Printer.java +++ b/delegation/src/main/java/com/iluwatar/delegation/simple/Printer.java @@ -38,7 +38,8 @@ public interface Printer { /** * Method that takes a String to print to the screen. This will be implemented on both the - * controller and the delegate allowing the controller to call the same method on the delegate class. + * controller and the delegate allowing the controller to call the same method on the delegate + * class. * * @param message to be printed to the screen */ diff --git a/delegation/src/main/java/com/iluwatar/delegation/simple/PrinterController.java b/delegation/src/main/java/com/iluwatar/delegation/simple/PrinterController.java index 315b6ee58..add1d71e6 100644 --- a/delegation/src/main/java/com/iluwatar/delegation/simple/PrinterController.java +++ b/delegation/src/main/java/com/iluwatar/delegation/simple/PrinterController.java @@ -24,10 +24,10 @@ package com.iluwatar.delegation.simple; /** - * Delegator Class to delegate the implementation of the Printer. - * This ensures two things: - * - when the actual implementation of the Printer class changes the delegation will still be operational - * - the actual benefit is observed when there are more than one implementors and they share a delegation control + * Delegator Class to delegate the implementation of the Printer. This ensures two things: - when + * the actual implementation of the Printer class changes the delegation will still be operational - + * the actual benefit is observed when there are more than one implementors and they share a + * delegation control */ public class PrinterController implements Printer { @@ -38,10 +38,10 @@ public class PrinterController implements Printer { } /** - * This method is implemented from {@link Printer} however instead on providing an - * implementation, it instead calls upon the class passed through the constructor. This is the delegate, - * hence the pattern. Therefore meaning that the caller does not care of the implementing class only the owning - * controller. + * This method is implemented from {@link Printer} however instead on providing an implementation, + * it instead calls upon the class passed through the constructor. This is the delegate, hence the + * pattern. Therefore meaning that the caller does not care of the implementing class only the + * owning controller. * * @param message to be printed to the screen */ diff --git a/delegation/src/main/java/com/iluwatar/delegation/simple/printers/CanonPrinter.java b/delegation/src/main/java/com/iluwatar/delegation/simple/printers/CanonPrinter.java index 9188fc988..5d7c59c86 100644 --- a/delegation/src/main/java/com/iluwatar/delegation/simple/printers/CanonPrinter.java +++ b/delegation/src/main/java/com/iluwatar/delegation/simple/printers/CanonPrinter.java @@ -28,8 +28,8 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; /** - * Specialised Implementation of {@link Printer} for a Canon Printer, in - * this case the message to be printed is appended to "Canon Printer : " + * Specialised Implementation of {@link Printer} for a Canon Printer, in this case the message to be + * printed is appended to "Canon Printer : ". * * @see Printer */ diff --git a/delegation/src/main/java/com/iluwatar/delegation/simple/printers/EpsonPrinter.java b/delegation/src/main/java/com/iluwatar/delegation/simple/printers/EpsonPrinter.java index a29c0b224..67bd00ac8 100644 --- a/delegation/src/main/java/com/iluwatar/delegation/simple/printers/EpsonPrinter.java +++ b/delegation/src/main/java/com/iluwatar/delegation/simple/printers/EpsonPrinter.java @@ -28,8 +28,8 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; /** - * Specialised Implementation of {@link Printer} for a Epson Printer, in - * this case the message to be printed is appended to "Epson Printer : " + * Specialised Implementation of {@link Printer} for a Epson Printer, in this case the message to be + * printed is appended to "Epson Printer : ". * * @see Printer */ diff --git a/delegation/src/main/java/com/iluwatar/delegation/simple/printers/HpPrinter.java b/delegation/src/main/java/com/iluwatar/delegation/simple/printers/HpPrinter.java index cb0a8068d..082e0054a 100644 --- a/delegation/src/main/java/com/iluwatar/delegation/simple/printers/HpPrinter.java +++ b/delegation/src/main/java/com/iluwatar/delegation/simple/printers/HpPrinter.java @@ -28,8 +28,8 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; /** - * Specialised Implementation of {@link Printer} for a HP Printer, in - * this case the message to be printed is appended to "HP Printer : " + * Specialised Implementation of {@link Printer} for a HP Printer, in this case the message to be + * printed is appended to "HP Printer : ". * * @see Printer */ diff --git a/dependency-injection/src/main/java/com/iluwatar/dependency/injection/AdvancedSorceress.java b/dependency-injection/src/main/java/com/iluwatar/dependency/injection/AdvancedSorceress.java index 0009cfadc..31f4e78bf 100644 --- a/dependency-injection/src/main/java/com/iluwatar/dependency/injection/AdvancedSorceress.java +++ b/dependency-injection/src/main/java/com/iluwatar/dependency/injection/AdvancedSorceress.java @@ -23,30 +23,6 @@ package com.iluwatar.dependency.injection; -/** - * The MIT License - * Copyright (c) 2014-2017 Ilkka Seppälä - *
- * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - *
- * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - */ - - /** * AdvancedSorceress implements inversion of control. It depends on abstraction that can be injected * through its setter. diff --git a/dependency-injection/src/main/java/com/iluwatar/dependency/injection/AdvancedWizard.java b/dependency-injection/src/main/java/com/iluwatar/dependency/injection/AdvancedWizard.java index e57222b19..e0c952186 100644 --- a/dependency-injection/src/main/java/com/iluwatar/dependency/injection/AdvancedWizard.java +++ b/dependency-injection/src/main/java/com/iluwatar/dependency/injection/AdvancedWizard.java @@ -24,10 +24,8 @@ package com.iluwatar.dependency.injection; /** - * * AdvancedWizard implements inversion of control. It depends on abstraction that can be injected * through its constructor. - * */ public class AdvancedWizard implements Wizard { diff --git a/dependency-injection/src/main/java/com/iluwatar/dependency/injection/App.java b/dependency-injection/src/main/java/com/iluwatar/dependency/injection/App.java index 0c829b98b..79c6400b1 100644 --- a/dependency-injection/src/main/java/com/iluwatar/dependency/injection/App.java +++ b/dependency-injection/src/main/java/com/iluwatar/dependency/injection/App.java @@ -31,25 +31,26 @@ import com.google.inject.Injector; * 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. * - Abstractions should not depend on details. Details should depend on abstractions. - *
- * 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 + * + *
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 which cannot be changed. - *
- * The second and third wizards({@link AdvancedWizard} and {@link AdvancedSorceress}) are more flexible. - * They do not depend on any concrete implementation but abstraction. They utilizes Dependency Injection - * pattern allowing their {@link Tobacco} dependency to be injected through constructor ({@link AdvancedWizard}) - * or setter ({@link AdvancedSorceress}). This way, handling the dependency is no longer the wizard's - * responsibility. It is resolved outside the wizard class. - *
- * The fourth example takes the pattern a step further. It uses Guice framework for Dependency + * + *
The second and third wizards({@link AdvancedWizard} and {@link AdvancedSorceress}) are more + * flexible. They do not depend on any concrete implementation but abstraction. They utilizes + * Dependency Injection pattern allowing their {@link Tobacco} dependency to be injected through + * constructor ({@link AdvancedWizard}) or setter ({@link AdvancedSorceress}). This way, handling + * the dependency is no longer the wizard's responsibility. It is resolved outside the wizard + * class. + * + *
The fourth example takes the pattern a step further. It uses Guice framework for Dependency * Injection. {@link TobaccoModule} binds a concrete implementation to abstraction. Injector is then * used to create {@link GuiceWizard} object with correct dependencies. */ public class App { /** - * Program entry point + * Program entry point. * * @param args command line args */ diff --git a/dependency-injection/src/main/java/com/iluwatar/dependency/injection/GuiceWizard.java b/dependency-injection/src/main/java/com/iluwatar/dependency/injection/GuiceWizard.java index 33776ed1d..319a635eb 100644 --- a/dependency-injection/src/main/java/com/iluwatar/dependency/injection/GuiceWizard.java +++ b/dependency-injection/src/main/java/com/iluwatar/dependency/injection/GuiceWizard.java @@ -26,10 +26,8 @@ package com.iluwatar.dependency.injection; import javax.inject.Inject; /** - * * GuiceWizard implements inversion of control. Its dependencies are injected through its * constructor by Guice framework. - * */ public class GuiceWizard implements Wizard { diff --git a/dependency-injection/src/main/java/com/iluwatar/dependency/injection/OldTobyTobacco.java b/dependency-injection/src/main/java/com/iluwatar/dependency/injection/OldTobyTobacco.java index b198a4c50..3f242ea60 100644 --- a/dependency-injection/src/main/java/com/iluwatar/dependency/injection/OldTobyTobacco.java +++ b/dependency-injection/src/main/java/com/iluwatar/dependency/injection/OldTobyTobacco.java @@ -24,9 +24,7 @@ package com.iluwatar.dependency.injection; /** - * - * OldTobyTobacco concrete {@link Tobacco} implementation - * + * OldTobyTobacco concrete {@link Tobacco} implementation. */ public class OldTobyTobacco extends Tobacco { } diff --git a/dependency-injection/src/main/java/com/iluwatar/dependency/injection/RivendellTobacco.java b/dependency-injection/src/main/java/com/iluwatar/dependency/injection/RivendellTobacco.java index 37c17fbfd..50ef5e2c5 100644 --- a/dependency-injection/src/main/java/com/iluwatar/dependency/injection/RivendellTobacco.java +++ b/dependency-injection/src/main/java/com/iluwatar/dependency/injection/RivendellTobacco.java @@ -24,9 +24,7 @@ package com.iluwatar.dependency.injection; /** - * - * RivendellTobacco concrete {@link Tobacco} implementation - * + * RivendellTobacco concrete {@link Tobacco} implementation. */ public class RivendellTobacco extends Tobacco { } diff --git a/dependency-injection/src/main/java/com/iluwatar/dependency/injection/SecondBreakfastTobacco.java b/dependency-injection/src/main/java/com/iluwatar/dependency/injection/SecondBreakfastTobacco.java index 9845c0381..622958615 100644 --- a/dependency-injection/src/main/java/com/iluwatar/dependency/injection/SecondBreakfastTobacco.java +++ b/dependency-injection/src/main/java/com/iluwatar/dependency/injection/SecondBreakfastTobacco.java @@ -24,9 +24,7 @@ package com.iluwatar.dependency.injection; /** - * - * SecondBreakfastTobacco concrete {@link Tobacco} implementation - * + * SecondBreakfastTobacco concrete {@link Tobacco} implementation. */ public class SecondBreakfastTobacco extends Tobacco { } diff --git a/dependency-injection/src/main/java/com/iluwatar/dependency/injection/SimpleWizard.java b/dependency-injection/src/main/java/com/iluwatar/dependency/injection/SimpleWizard.java index ef7dbd144..40bca0ffb 100644 --- a/dependency-injection/src/main/java/com/iluwatar/dependency/injection/SimpleWizard.java +++ b/dependency-injection/src/main/java/com/iluwatar/dependency/injection/SimpleWizard.java @@ -24,10 +24,8 @@ package com.iluwatar.dependency.injection; /** - * * Naive Wizard implementation violating the inversion of control principle. It should depend on * abstraction instead. - * */ public class SimpleWizard implements Wizard { diff --git a/dependency-injection/src/main/java/com/iluwatar/dependency/injection/Tobacco.java b/dependency-injection/src/main/java/com/iluwatar/dependency/injection/Tobacco.java index c3549b6a0..aaef6ba2a 100644 --- a/dependency-injection/src/main/java/com/iluwatar/dependency/injection/Tobacco.java +++ b/dependency-injection/src/main/java/com/iluwatar/dependency/injection/Tobacco.java @@ -27,9 +27,7 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; /** - * - * Tobacco abstraction - * + * Tobacco abstraction. */ public abstract class Tobacco { diff --git a/dependency-injection/src/main/java/com/iluwatar/dependency/injection/TobaccoModule.java b/dependency-injection/src/main/java/com/iluwatar/dependency/injection/TobaccoModule.java index 78b43ffa9..43cadc071 100644 --- a/dependency-injection/src/main/java/com/iluwatar/dependency/injection/TobaccoModule.java +++ b/dependency-injection/src/main/java/com/iluwatar/dependency/injection/TobaccoModule.java @@ -26,9 +26,7 @@ package com.iluwatar.dependency.injection; import com.google.inject.AbstractModule; /** - * * Guice module for binding certain concrete {@link Tobacco} implementation. - * */ public class TobaccoModule extends AbstractModule { diff --git a/dependency-injection/src/main/java/com/iluwatar/dependency/injection/Wizard.java b/dependency-injection/src/main/java/com/iluwatar/dependency/injection/Wizard.java index 6bdca7415..0575118a5 100644 --- a/dependency-injection/src/main/java/com/iluwatar/dependency/injection/Wizard.java +++ b/dependency-injection/src/main/java/com/iluwatar/dependency/injection/Wizard.java @@ -24,9 +24,7 @@ package com.iluwatar.dependency.injection; /** - * - * Wizard interface - * + * Wizard interface. */ public interface Wizard { diff --git a/dirty-flag/src/main/java/com/iluwatar/dirtyflag/App.java b/dirty-flag/src/main/java/com/iluwatar/dirtyflag/App.java index 7caaca561..cc9a69406 100644 --- a/dirty-flag/src/main/java/com/iluwatar/dirtyflag/App.java +++ b/dirty-flag/src/main/java/com/iluwatar/dirtyflag/App.java @@ -23,45 +23,49 @@ package com.iluwatar.dirtyflag; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - import java.util.List; import java.util.concurrent.Executors; import java.util.concurrent.ScheduledExecutorService; import java.util.concurrent.TimeUnit; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; /** + * This application demonstrates the Dirty Flag pattern. The dirty flag behavioral pattern + * allows you to avoid expensive operations that would just need to be done again anyway. This is a + * simple pattern that really just explains how to add a bool value to your class that you can set + * anytime a property changes. This will let your class know that any results it may have previously + * calculated will need to be calculated again when they’re requested. Once the results are + * re-calculated, then the bool value can be cleared. * - * This application demonstrates the Dirty Flag pattern. The dirty flag behavioral pattern allows you to avoid - * expensive operations that would just need to be done again anyway. This is a simple pattern that really just explains - * how to add a bool value to your class that you can set anytime a property changes. This will let your class know that - * any results it may have previously calculated will need to be calculated again when they’re requested. Once the - * results are re-calculated, then the bool value can be cleared. - * - * There are some points that need to be considered before diving into using this pattern:- there are some things you’ll - * need to consider:- (1) Do you need it? This design pattern works well when the results to be calculated are difficult - * or resource intensive to compute. You want to save them. You also don’t want to be calculating them several times in - * a row when only the last one counts. (2) When do you set the dirty flag? Make sure that you set the dirty flag within - * the class itself whenever an important property changes. This property should affect the result of the calculated - * result and by changing the property, that makes the last result invalid. (3) When do you clear the dirty flag? It - * might seem obvious that the dirty flag should be cleared whenever the result is calculated with up-to-date - * information but there are other times when you might want to clear the flag. + *
There are some points that need to be considered before diving into using this pattern:- + * there are some things you’ll need to consider:- (1) Do you need it? This design pattern works + * well when the results to be calculated are difficult or resource intensive to compute. You want + * to save them. You also don’t want to be calculating them several times in a row when only the + * last one counts. (2) When do you set the dirty flag? Make sure that you set the dirty flag within + * the class itself whenever an important property changes. This property should affect the result + * of the calculated result and by changing the property, that makes the last result invalid. (3) + * When do you clear the dirty flag? It might seem obvious that the dirty flag should be cleared + * whenever the result is calculated with up-to-date information but there are other times when you + * might want to clear the flag. * - * In this example, the {@link DataFetcher} holds the dirty flag. It fetches and re-fetches from world.txt - * when needed. {@link World} mainly serves the data to the front-end. + *
In this example, the {@link DataFetcher} holds the dirty flag. It fetches and
+ * re-fetches from world.txt when needed. {@link World} mainly serves the data to the
+ * front-end.
*/
public class App {
-
+
private static final Logger LOGGER = LoggerFactory.getLogger(App.class);
+
/**
- * Program execution point
+ * Program execution point.
*/
public void run() {
final ScheduledExecutorService executorService = Executors.newSingleThreadScheduledExecutor();
executorService.scheduleAtFixedRate(new Runnable() {
final World world = new World();
+
@Override
public void run() {
List
- * 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 use double checked locking to
- * add item to inventory. In this method, the thread which gets the lock first adds the item.
- *
+ *
+ * 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 use double checked
+ * locking to add item to inventory. In this method, the thread which gets the lock first adds the
+ * item.
*/
public class App {
private static final Logger LOGGER = LoggerFactory.getLogger(App.class);
/**
- * Program entry point
- *
+ * Program entry point.
+ *
* @param args command line args
*/
public static void main(String[] args) {
diff --git a/double-checked-locking/src/main/java/com/iluwatar/doublechecked/locking/Inventory.java b/double-checked-locking/src/main/java/com/iluwatar/doublechecked/locking/Inventory.java
index c13908b19..17b47fa43 100644
--- a/double-checked-locking/src/main/java/com/iluwatar/doublechecked/locking/Inventory.java
+++ b/double-checked-locking/src/main/java/com/iluwatar/doublechecked/locking/Inventory.java
@@ -23,19 +23,16 @@
package com.iluwatar.doublechecked.locking;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
/**
- *
- * Inventory
- *
+ * Inventory.
*/
public class Inventory {
@@ -46,7 +43,7 @@ public class Inventory {
private final Lock lock;
/**
- * Constructor
+ * Constructor.
*/
public Inventory(int inventorySize) {
this.inventorySize = inventorySize;
@@ -55,7 +52,7 @@ public class Inventory {
}
/**
- * Add item
+ * Add item.
*/
public boolean addItem(Item item) {
if (items.size() < inventorySize) {
@@ -63,7 +60,8 @@ public class Inventory {
try {
if (items.size() < inventorySize) {
items.add(item);
- LOGGER.info("{}: items.size()={}, inventorySize={}", Thread.currentThread(), items.size(), inventorySize);
+ LOGGER.info("{}: items.size()={}, inventorySize={}", Thread.currentThread(), items
+ .size(), inventorySize);
return true;
}
} finally {
@@ -74,7 +72,7 @@ public class Inventory {
}
/**
- * Get all the items in the inventory
+ * Get all the items in the inventory.
*
* @return All the items of the inventory, as an unmodifiable list
*/
diff --git a/double-checked-locking/src/main/java/com/iluwatar/doublechecked/locking/Item.java b/double-checked-locking/src/main/java/com/iluwatar/doublechecked/locking/Item.java
index c2c5559d0..ecedc535f 100644
--- a/double-checked-locking/src/main/java/com/iluwatar/doublechecked/locking/Item.java
+++ b/double-checked-locking/src/main/java/com/iluwatar/doublechecked/locking/Item.java
@@ -24,9 +24,7 @@
package com.iluwatar.doublechecked.locking;
/**
- *
- * Item
- *
+ * Item.
*/
public class Item {
}
diff --git a/double-dispatch/src/main/java/com/iluwatar/doubledispatch/App.java b/double-dispatch/src/main/java/com/iluwatar/doubledispatch/App.java
index e6b670a6d..9117ede47 100644
--- a/double-dispatch/src/main/java/com/iluwatar/doubledispatch/App.java
+++ b/double-dispatch/src/main/java/com/iluwatar/doubledispatch/App.java
@@ -23,46 +23,45 @@
package com.iluwatar.doubledispatch;
+import java.util.List;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import java.util.List;
-
/**
- *
- * 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 by the type of the 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 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.
- *
- * 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 implementation (open-closed principle).
- *
- * 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 there is an overlap, then the objects
- * collide utilizing the Double Dispatch pattern.
+ * 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 by
+ * the type of the 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 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.
+ *
+ * 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 implementation (open-closed principle).
+ *
+ * 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 there is an overlap, then the objects collide utilizing the Double Dispatch
+ * pattern.
*/
public class App {
private static final Logger LOGGER = LoggerFactory.getLogger(App.class);
/**
- * Program entry point
- *
- * @param args
- * command line args
+ * Program entry point.
+ *
+ * @param args command line args
*/
public static void main(String[] args) {
// initialize game objects and print their status
List