• Post Reply Bookmark Topic Watch Topic
  • New Topic

Why implement a callback?  RSS feed

 
Matt Senecal
Ranch Hand
Posts: 255
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This is something I've been pondering for a while, and I'd appreciate some solid guidance on the matter: If you have an object that needs to call a method in the class that created it, why not just pass the object a reference to "this" (i.e to the parent class as a whole)? The created object can just call the method it needs directly. The process of creating an interface and implementing it just seems to me like adding another layer.
 
Ernest Friedman-Hill
author and iconoclast
Sheriff
Posts: 24217
38
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Because if you did that, then the object that needed to call the method (TOTNTCTM) would be hard-wired to only work with the creating class. The interface does, indeed, add another layer, but it's only the indirection added by that layer that lets TOTNTCTM work with multiple different clients.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!