
Interface returns user defined type???
Quote:
> How to implement an interface that needs to return a user
> defined type. In the following, class NNN.Menu implements
> IMenu. Method GetFeatures returns an ArrayList of a user
> defined type, which is defined in the implementing class.
> This does not work because the clients would only have the
> interface not the implementation. It does not know the
> class FeaturePath.
Well, to put it simply, the client will *have* to have the FeaturePath
class. If you're putting an object in an ArrayList and the client
doesn't know anything about that object's class, it's going to have no
way of using it.
You could make FeaturePath implement another interface, and only expose
that *interface* to the client, however.
That's in terms of just "calling code" vs "library code" though - when
it comes to client/server communications, I believe you'll need to
specify how you're communicating first - if you're remoting, you may be
able to just get away with exposing the interface (I'm not sure). If the
object itself is actually passed down the wire, then the client will
need the actual concrete class.
--
http://www.pobox.com/~skeet/
If replying to the group, please do not mail me too