The moose likes OO, Patterns, UML and Refactoring and the fly likes explicit delegation by interface Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » OO, Patterns, UML and Refactoring
Bookmark "explicit delegation by interface" Watch "explicit delegation by interface" New topic

explicit delegation by interface

manuel aldana
Ranch Hand

Joined: Dec 29, 2005
Posts: 308

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!

aldana software engineering blog & .more
Frank Carver

Joined: Jan 07, 1999
Posts: 6920
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.

Read about me at ~ Raspberry Alpha Omega ~ Frank's Punchbarrel Blog
I agree. Here's the link:
subject: explicit delegation by interface
It's not a secret anymore!