mirror of
https://github.com/tiennm99/java-design-patterns.git
synced 2026-08-07 18:23:16 +00:00
docs: update delegation
This commit is contained in:
@@ -38,9 +38,9 @@ import com.iluwatar.delegation.simple.printers.HpPrinter;
|
||||
*
|
||||
* <p>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
|
||||
* 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.
|
||||
* instantiated with. Therefore, delegating the behaviour to another class.
|
||||
*/
|
||||
public class App {
|
||||
|
||||
|
||||
@@ -27,7 +27,7 @@ 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
|
||||
* the actual benefit is observed when there are more than one implementor, and they share a
|
||||
* delegation control
|
||||
*/
|
||||
public class PrinterController implements Printer {
|
||||
@@ -41,7 +41,7 @@ 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
|
||||
* 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
|
||||
|
||||
@@ -28,7 +28,7 @@ import com.iluwatar.delegation.simple.Printer;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
/**
|
||||
* Specialised Implementation of {@link Printer} for a Epson Printer, in this case the message to be
|
||||
* Specialised Implementation of {@link Printer} for an Epson Printer, in this case the message to be
|
||||
* printed is appended to "Epson Printer : ".
|
||||
*
|
||||
* @see Printer
|
||||
|
||||
@@ -28,7 +28,7 @@ import com.iluwatar.delegation.simple.Printer;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
/**
|
||||
* Specialised Implementation of {@link Printer} for a HP Printer, in this case the message to be
|
||||
* Specialised Implementation of {@link Printer} for an HP Printer, in this case the message to be
|
||||
* printed is appended to "HP Printer : ".
|
||||
*
|
||||
* @see Printer
|
||||
|
||||
@@ -35,7 +35,6 @@ class AppTest {
|
||||
|
||||
/**
|
||||
* Issue: Add at least one assertion to this test case.
|
||||
*
|
||||
* Solution: Inserted assertion to check whether the execution of the main method in {@link App#main(String[])}
|
||||
* throws an exception.
|
||||
*/
|
||||
|
||||
@@ -59,7 +59,7 @@ class DelegateTest {
|
||||
private static final String MESSAGE = "Test Message Printed";
|
||||
|
||||
@Test
|
||||
void testCanonPrinter() throws Exception {
|
||||
void testCanonPrinter() {
|
||||
var printerController = new PrinterController(new CanonPrinter());
|
||||
printerController.print(MESSAGE);
|
||||
|
||||
@@ -67,7 +67,7 @@ class DelegateTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
void testHpPrinter() throws Exception {
|
||||
void testHpPrinter() {
|
||||
var printerController = new PrinterController(new HpPrinter());
|
||||
printerController.print(MESSAGE);
|
||||
|
||||
@@ -75,7 +75,7 @@ class DelegateTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
void testEpsonPrinter() throws Exception {
|
||||
void testEpsonPrinter() {
|
||||
var printerController = new PrinterController(new EpsonPrinter());
|
||||
printerController.print(MESSAGE);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user