This week's book giveaway is in the OCMJEA forum.
We're giving away four copies of OCM Java EE 6 Enterprise Architect Exam Guide and have Paul Allen & Joseph Bambara on-line!
See this thread for details.
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


Win a copy of OCM Java EE 6 Enterprise Architect Exam Guide this week in the OCMJEA forum!
JavaRanch » Java Forums » Engineering » OO, Patterns, UML and Refactoring
Bookmark "explicit delegation by interface" Watch "explicit delegation by interface" New topic
Author

explicit delegation by interface

manuel aldana
Ranch Hand

Joined: Dec 29, 2005
Posts: 308
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!


aldana software engineering blog & .more
Frank Carver
Sheriff

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 frankcarver.me ~ Raspberry Alpha Omega ~ Frank's Punchbarrel Blog
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: explicit delegation by interface