0 likes | 18 Views
<br>The delegation pattern is a technique where an object expresses a certain behavior to the outside but simultaneously delegates responsibility for implementing that behavior to an associated object.<br>
E N D
The delegation pattern is a technique where an object expresses a certain behavior to the outside but simultaneously delegates responsibility for implementing that behavior to an associated object.Let's understand this with the help of an example:Let's say we want a printer. And a printer does what it is supposed to do. Let's create an interface to show this behavior. interface Printer { void print(final String message); } https://erpsolutions.oodles.io/developer-blogs/Delegation-Pattern-and-The-By-Keyword/
Now it does not matter which printer prints this. So let's say we have Three Printers(Canon, Epson, and HP) . Whichever printer is available or has ink prints the text. Now all of them are of type printers so all three will implement the Printer interface. class CanonPrinter implements Printer { @Override public void print(String message) { System.out.println("Canon Printer : "+message ); } } class EpsonPrinter implements Printer { @Override public void print(String message) { System.out.println("Epson Printer : {}"+message); } }