Hi Mattias,
Yep,
that is a weakness with my idea given the current semantics.
I guess what I am proposing here would need to be some sort of 'Sealed
Interface'
i.e. You can only declare say a 'IFordFactory' or a 'IToyotaFactory '
My real world situation that led to this line of reasoning is:
AppA has an internal widgetprocessin g class
AppB also processes widgets but does it using a DLL because it is
fundamentally different to AppA
Along comes a third party SuperWidgetProc essor class library that I want to
bolt on to AppA and also make available to AppB users who may or may not
decide to take it on board.
So I wrap SuperWidgetProc essor and expose its functionality through two
interfaces say IA and IB.
Easiest way to insert into AppA is to have the AppA WidgetProcessin g class
declare a private IA and route all its functionality to it. This way all
changes are confined to the WidgetProcessin g class.
Trouble is that the other classes tell the WidgetProcessin g class what they
want by passing in a request class that has Properties based on enums. So my
wrapper exposes a set of identically named enums and the routing code is
readable.
AppB uses a completely different approach so the enum thing is not needed.
So..
I am left with a wrapper that has a public enum that is useful to only one
out of two interfaces.
Hence my current line of reasoning of wanting to expose the enum only
through IA.
Ah well,
Perhaps in another life.
Thank you all for your thoughts.
regards
Bob
"Mattias Sjögren" <ma************ ********@mvps.o rgwrote in message
news:OU******** ******@TK2MSFTN GP04.phx.gbl...
In the client code
Once the ; is typed in
ICarFactory factory = new FordFactory();
Intellisense knows the contents of ModelEnum from its inspection of the
FordFactory implementation
No it doesn't. IntelliSense looks at the type of the variable. It
doesn't know about the actual implementing type used at runtime. Your
example is too simplistic. When using interfaces, it's very common to
not know the actual type that will be used.
Take a look at this for example
void Foo(bool preferAmericanC ars)
{
ICarFactory factory;
if (preferAmerican Car)
factory = new FordFactory();
else
factory = new ToyotaFactory() ;
factory.MakeCar (...
At this point, which "implementation " of the enum would you use? And
how would IntelliSense and the compiler know?
Mattias
--
Mattias Sjögren [C# MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.