1 / 3

Delegation Pattern and The By Keyword

<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>

BabyFlix
Download Presentation

Delegation Pattern and The By Keyword

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Delegation Pattern and The By Keyword

  2. 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/

  3. 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); } }

More Related