Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

explicit delegation by interface  RSS feed

 
manuel aldana
Ranch Hand
Posts: 308
  • 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
  • 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.
 
Don't get me started about those stupid light bulbs.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!