• Post Reply Bookmark Topic Watch Topic
  • New Topic

Contained Class Implementing the Same Interface as the Container - UrlyBird 1.1.1  RSS feed

Thomas Hubschman
Ranch Hand
Posts: 88
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Ranchers,

Is it bad, how bad is it, and is there another way to get around a contained class implementing the same interface as the container class, with the container class having pass through method implementations to the contained class.

In my particular case the container class is Data which contains a reference to the Storage class but provides the additional functionality of locking and finding (finding through a cache). The Storage class presents only data altering methods.

The issue is that I want to add a 'DBSchema' interface that provides the following methods:

It seems to me that what makes the most sense is to have the Data class AND the Storage class both implement this interface. Although in the case of the Data class it is just passing through calls to the contained Storage class. The Data class needs to implement the interface so that external callers can continue to use an interface to access the Data class rather than an instance reference.

That seems icky to me.... but I am not sure. I searched around on Google for a bit, but didn't find an answer there.

Any help as always would be appreciated.


It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!