File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

explicit delegation by interface

 
manuel aldana
Ranch Hand
Posts: 308
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi,

i am having a class which is delegating methods to another class, which implements an interface.
i thought about making the delegation explicit by implementing the interface of the delegating class.

i am having following code:


now my idea is to explicitly delegate by having the wrapper A implement the interface, too:


in my view it is alright because all methods are making sense in the view of A and therefore should not be confusing for the user. on the other hand i am a bit unsure, because i rarely see this way to show the delegation in the type declaration.

by the way: it is not applicable to inline B to A, because otherwise A would be too big.

thanks for your thoughts!
 
Frank Carver
Sheriff
Posts: 6920
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This looks a lot like the Decorator pattern to me. I use that a lot. In particular, I always add an "implements" if a decorating class does actually provide the methods of the interface (with the same signatures), so that it in turn may be decorated if needed.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic