mirror of
https://github.com/tiennm99/java-design-patterns.git
synced 2026-06-07 20:15:13 +00:00
Added skeleton code for delegation pattern #324
This commit is contained in:
@@ -0,0 +1,14 @@
|
||||
package com.iluwatar.delegation.simple;
|
||||
|
||||
public abstract class Controller<T extends Printer> {
|
||||
|
||||
private Printer printer;
|
||||
|
||||
public Controller(Printer printer) {
|
||||
this.printer = printer;
|
||||
}
|
||||
|
||||
protected Printer getPrinter() {
|
||||
return printer;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
package com.iluwatar.delegation.simple;
|
||||
|
||||
public interface Printer {
|
||||
|
||||
void print(final String message);
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
package com.iluwatar.delegation.simple;
|
||||
|
||||
public class PrinterController extends Controller implements Printer {
|
||||
|
||||
public PrinterController(Printer printer) {
|
||||
super(printer);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void print(String message) {
|
||||
getPrinter().print(message);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
package com.iluwatar.delegation.simple.printers;
|
||||
|
||||
import com.iluwatar.delegation.simple.Printer;
|
||||
|
||||
public class CanonPrinter implements Printer {
|
||||
|
||||
@Override
|
||||
public void print(String message) {
|
||||
System.out.println("Canon Printer : " + message);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
package com.iluwatar.delegation.simple.printers;
|
||||
|
||||
import com.iluwatar.delegation.simple.Printer;
|
||||
|
||||
public class EpsonPrinter implements Printer{
|
||||
|
||||
@Override
|
||||
public void print(String message) {
|
||||
System.out.println("Epson Printer : " + message);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
package com.iluwatar.delegation.simple.printers;
|
||||
|
||||
import com.iluwatar.delegation.simple.Printer;
|
||||
|
||||
public class HPPrinter implements Printer {
|
||||
|
||||
@Override
|
||||
public void print(String message) {
|
||||
System.out.println("HP Printer : " + message);
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user