tags:

views:

47

answers:

1

Consider the following simplified demonstration: Class X contain class Y. Class Y has public method, Y.doY Stuff().

How to design X interface which use Y methods as is?

If one append public method to X which simply forward the requst to Y, it results in an undesirable fat X interface and dependency of X code to Y code. This approach gets worst at multiply containment.

If one use indirect access, such as X.Y.doYStuff(), it becomes a much cleaner design, but results in breaking the X encapsulation.

So, is there a clean and correct design which enables using methods of inner class out of there wrapper class?

A: 

It seems that the design you are using is a tad backwards.

From your description you don't particularly want to have direct Y methods in your X interface, so why not have a secondary interface Z for example sake. This way the interfaces will be more specific and you can implement both interfaces on the objects you need them.

This results in two smaller interfaces, but with larger flexibility.

Alternatively, you could create an abstract class Z, using the X interface. Then you just need to inherit Y from Z and can do a base() or super() construct to gain the functionality you need.

Both should work for you.

Kyle Rozendo