Add simple tests for delegate pattern #324

This commit is contained in:
Joseph McCarthy
2015-12-27 14:10:49 +00:00
parent fb0617e9c5
commit a49dbefb56
5 changed files with 56 additions and 11 deletions
@@ -1,10 +1,10 @@
package com.iluwatar.delegation.simple;
public abstract class Controller<T extends Printer> {
public abstract class AbstractPrinterController<T extends Printer> implements Printer{
private Printer printer;
public Controller(Printer printer) {
public AbstractPrinterController(Printer printer) {
this.printer = printer;
}
@@ -1,6 +1,6 @@
package com.iluwatar.delegation.simple;
public class PrinterController extends Controller implements Printer {
public class PrinterController extends AbstractPrinterController {
public PrinterController(Printer printer) {
super(printer);
@@ -1,6 +1,6 @@
package com.iluwatar.delegation.simple.printers;
import com.iluwatar.delegation.simple.Printer;
import com.iluwatar.delegation.simple.AbstractPrinterController;
import com.iluwatar.delegation.simple.PrinterController;
public class App {
@@ -8,13 +8,9 @@ public class App {
public static final String MESSAGE_TO_PRINT = "hello world";
public static void main(String[] args) {
Printer hpPrinter = new HPPrinter();
Printer canonPrinter = new CanonPrinter();
Printer epsonPrinter = new EpsonPrinter();
PrinterController hpPrinterController = new PrinterController(hpPrinter);
PrinterController canonPrinterController = new PrinterController(canonPrinter);
PrinterController epsonPrinterController = new PrinterController(epsonPrinter);
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);