diff --git a/delegation/src/main/java/com/iluwatar/delegation/simple/AbstractPrinterController.java b/delegation/src/main/java/com/iluwatar/delegation/simple/AbstractPrinterController.java index 679c1a3a6..4baf41a88 100644 --- a/delegation/src/main/java/com/iluwatar/delegation/simple/AbstractPrinterController.java +++ b/delegation/src/main/java/com/iluwatar/delegation/simple/AbstractPrinterController.java @@ -2,8 +2,8 @@ package com.iluwatar.delegation.simple; /** * Extra layer of abstraction for the controller to allow the controller in this example {@link PrinterController} to - * be as clean as possible. This just provides the default constructor and a simple getter method. The generic of T allows - * any implementation of {@link Printer} + * be as clean as possible. This just provides the default constructor and a simple getter method. The generic of + * T allows any implementation of {@link Printer} * * @param Printer * @see Printer @@ -12,23 +12,23 @@ package com.iluwatar.delegation.simple; public abstract class AbstractPrinterController implements Printer { - private T printer; + private T printer; - /** - * @param printer instance of T {@link Printer} this instance is the delegate - */ - public AbstractPrinterController(T printer) { - this.printer = printer; - } + /** + * @param printer instance of T {@link Printer} this instance is the delegate + */ + public AbstractPrinterController(T printer) { + this.printer = printer; + } - /** - * Helper method to return the current instance of T {@link Printer} in order for - * the controller to call operations on the {@link Printer} - * - * @return instance of Printer - * @see Printer - */ - protected T getPrinter() { - return printer; - } + /** + * Helper method to return the current instance of T {@link Printer} in order for + * the controller to call operations on the {@link Printer} + * + * @return instance of Printer + * @see Printer + */ + protected T getPrinter() { + return printer; + } } 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 47cf27e8e..f0a55cc4c 100644 --- a/delegation/src/main/java/com/iluwatar/delegation/simple/App.java +++ b/delegation/src/main/java/com/iluwatar/delegation/simple/App.java @@ -2,32 +2,32 @@ package com.iluwatar.delegation.simple; import com.iluwatar.delegation.simple.printers.CanonPrinter; import com.iluwatar.delegation.simple.printers.EpsonPrinter; -import com.iluwatar.delegation.simple.printers.HPPrinter; +import com.iluwatar.delegation.simple.printers.HpPrinter; /** - * In this example the delegates are {@link EpsonPrinter}, {@link HPPrinter} and {@link CanonPrinter} they all implement - * {@link Printer}. The {@link AbstractPrinterController} and through inheritance {@link PrinterController} also implement - * {@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 AbstractPrinterController} and through inheritance {@link PrinterController} also + * implement {@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 { - public static final String MESSAGE_TO_PRINT = "hello world"; + public static final String MESSAGE_TO_PRINT = "hello world"; - /** - * Program entry point - * - * @param args command line args - */ - public static void main(String[] args) { - AbstractPrinterController hpPrinterController = new PrinterController(new HPPrinter()); - AbstractPrinterController canonPrinterController = new PrinterController(new CanonPrinter()); - AbstractPrinterController epsonPrinterController = new PrinterController(new EpsonPrinter()); + /** + * Program entry point + * + * @param args command line args + */ + public static void main(String[] args) { + AbstractPrinterController hpPrinterController = new PrinterController(new HpPrinter()); + AbstractPrinterController canonPrinterController = new PrinterController(new CanonPrinter()); + AbstractPrinterController epsonPrinterController = new PrinterController(new EpsonPrinter()); - hpPrinterController.print(MESSAGE_TO_PRINT); - canonPrinterController.print(MESSAGE_TO_PRINT); - epsonPrinterController.print(MESSAGE_TO_PRINT); - } + hpPrinterController.print(MESSAGE_TO_PRINT); + canonPrinterController.print(MESSAGE_TO_PRINT); + epsonPrinterController.print(MESSAGE_TO_PRINT); + } } 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 aa3bebfda..d7a2fd7ca 100644 --- a/delegation/src/main/java/com/iluwatar/delegation/simple/Printer.java +++ b/delegation/src/main/java/com/iluwatar/delegation/simple/Printer.java @@ -1,20 +1,22 @@ package com.iluwatar.delegation.simple; +import com.iluwatar.delegation.simple.printers.HpPrinter; + /** - * Interface that both the Controller and the Delegate will implement. + * Interface that both the Controller and the Delegate will implement. * - * @see com.iluwatar.delegation.simple.printers.CanonPrinter - * @see com.iluwatar.delegation.simple.printers.EpsonPrinter - * @see com.iluwatar.delegation.simple.printers.HPPrinter - * @see AbstractPrinterController + * @see com.iluwatar.delegation.simple.printers.CanonPrinter + * @see com.iluwatar.delegation.simple.printers.EpsonPrinter + * @see HpPrinter + * @see AbstractPrinterController */ 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. - * - * @param message to be printed to the screen - */ - void print(final String message); + /** + * 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. + * + * @param message to be printed to the screen + */ + void print(final String message); } 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 98be53a2b..7197ba2ed 100644 --- a/delegation/src/main/java/com/iluwatar/delegation/simple/PrinterController.java +++ b/delegation/src/main/java/com/iluwatar/delegation/simple/PrinterController.java @@ -2,20 +2,20 @@ package com.iluwatar.delegation.simple; public class PrinterController extends AbstractPrinterController { - public PrinterController(Printer printer) { - super(printer); - } + public PrinterController(Printer printer) { + super(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. - * - * @param message to be printed to the screen - */ - @Override - public void print(String message) { - getPrinter().print(message); - } + /** + * 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 + */ + @Override + public void print(String message) { + getPrinter().print(message); + } } 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 a55e1984d..c11495121 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 @@ -10,12 +10,12 @@ import com.iluwatar.delegation.simple.Printer; */ public class CanonPrinter implements Printer { - /** - * {@inheritDoc} - */ - @Override - public void print(String message) { - System.out.println("Canon Printer : " + message); - } + /** + * {@inheritDoc} + */ + @Override + public void print(String message) { + System.out.println("Canon Printer : " + message); + } } 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 bc53e2cae..be494ce94 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 @@ -8,14 +8,14 @@ import com.iluwatar.delegation.simple.Printer; * * @see Printer */ -public class EpsonPrinter implements Printer{ +public class EpsonPrinter implements Printer { - /** - * {@inheritDoc} - */ - @Override - public void print(String message) { - System.out.println("Epson Printer : " + message); - } + /** + * {@inheritDoc} + */ + @Override + public void print(String message) { + System.out.println("Epson Printer : " + message); + } } 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 e801ecdf0..a8f57e764 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 @@ -8,14 +8,14 @@ import com.iluwatar.delegation.simple.Printer; * * @see Printer */ -public class HPPrinter implements Printer { +public class HpPrinter implements Printer { - /** - * {@inheritDoc} - */ - @Override - public void print(String message) { - System.out.println("HP Printer : " + message); - } + /** + * {@inheritDoc} + */ + @Override + public void print(String message) { + System.out.println("HP Printer : " + message); + } } diff --git a/delegation/src/test/java/com/iluwatar/delegation/simple/DelegateTest.java b/delegation/src/test/java/com/iluwatar/delegation/simple/DelegateTest.java index db8cb4262..b184f52f2 100644 --- a/delegation/src/test/java/com/iluwatar/delegation/simple/DelegateTest.java +++ b/delegation/src/test/java/com/iluwatar/delegation/simple/DelegateTest.java @@ -2,7 +2,7 @@ package com.iluwatar.delegation.simple; import com.iluwatar.delegation.simple.printers.CanonPrinter; import com.iluwatar.delegation.simple.printers.EpsonPrinter; -import com.iluwatar.delegation.simple.printers.HPPrinter; +import com.iluwatar.delegation.simple.printers.HpPrinter; import org.junit.Rule; import org.junit.Test; import org.junit.contrib.java.lang.system.SystemOutRule; @@ -26,7 +26,7 @@ public class DelegateTest { @Test public void testHPPrinter() throws Exception { - AbstractPrinterController abstractController = new PrinterController(new HPPrinter()); + AbstractPrinterController abstractController = new PrinterController(new HpPrinter()); abstractController.print(MESSAGE); assertEquals("HP Printer : Test Message Printed\n", systemOutRule.getLog());