diff --git a/delegation/README.md b/delegation/README.md index 7774c5694..d9a9be688 100644 --- a/delegation/README.md +++ b/delegation/README.md @@ -3,7 +3,9 @@ title: Delegation category: Behavioral language: en tag: + - Decoupling - Delegation + - Object composition --- ## Also known as @@ -13,7 +15,7 @@ tag: ## Intent -The Delegation pattern in Java allows an object to delegate one or more tasks to a helper object. It is a technique where an object expresses certain behavior but actually delegates responsibility for implementing that behavior to an associated helper object. +To allow an object to delegate responsibility for a task to another helper object. ## Explanation @@ -27,6 +29,8 @@ Wikipedia says **Programmatic Example** +Let's consider a printing example. + We have an interface `Printer` and three implementations `CanonPrinter`, `EpsonPrinter` and `HpPrinter`. ```java @@ -59,8 +63,7 @@ public class HpPrinter implements Printer { } ``` -The `PrinterController` can be used as a `Printer` by delegating any work handled by this -interface to an object implementing it. +The `PrinterController` can be used as a `Printer` by delegating any work handled by this interface to an object implementing it. ```java public class PrinterController implements Printer { @@ -78,8 +81,7 @@ public class PrinterController implements Printer { } ``` -Now on the client code printer controllers can print messages differently depending on the -object they're delegating that work to. +Now on the client code printer controllers can print messages differently depending on the object they're delegating that work to. ```java public class App {