BhuttCrackSpackle

Since you cannot do this...

Dim MySpanningInterface as ISpanInterface = new (Class1, Class2)

My problem is, I am trying to take a series of classes and present parts of each of them to client programmers in a way that's convenient for them to program against.

The classes belong logically apart, but certain members of each class are needed for certain kinds of things.

I want a simple way to let programmers work against selected methods from more than one class through a single variable reference... hopefully an interface reference.

Is this possible How would you suggest doing this




Re: .NET Base Class Library Is it possible for an interface to span multiple classes?

Mike Stall - MSFT

You could create a single proxy class that has references to Class1, Class2, ... ClassN, and then wraps the methods you wish to expose. The proxy can thus expose a single interface.

It can also deal with any potential overlap in classes (eg, if 2 classes both have a Foo() method). It can also hide the parts of classes that you don't want expose (by simply not wrapping them).






Re: .NET Base Class Library Is it possible for an interface to span multiple classes?

BhuttCrackSpackle

Yeah, I thought about doing it this way, but I didn't want to end up duplicating the property definitions in the wrapper class. I also thought about maybe giving in and combining the separate classes into a single class, and then making an interface for each type of desired access.

I'm hoping maybe there's a third more clever way that I'm not thinking of.






Re: .NET Base Class Library Is it possible for an interface to span multiple classes?

Kim Major

Look at the Facade pattern. If you have several clients working with different parts of the public interface of the facade I would in addition create client specific interfaces grouping functionality. For more on the latter, look at the "interface segragation principle".