Delegation Pattern and The By Keyword - PowerPoint PPT Presentation

About This Presentation
Title:

Delegation Pattern and The By Keyword

Description:

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. – PowerPoint PPT presentation

Number of Views:0
Date added: 19 March 2024
Slides: 4
Provided by: oodlesERPsolutions
Category: Other
Tags:

less

Transcript and Presenter's Notes

Title: Delegation Pattern and The By Keyword


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 exampleLet'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/Del
    egation-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
  • _at_Override
  • public void print(String message)
  • System.out.println("Canon Printer "message )
  • class EpsonPrinter implements Printer
  • _at_Override
  • public void print(String message)
  • System.out.println("Epson Printer
    "message)
Write a Comment
User Comments (0)
About PowerShow.com