Multiple matching interfaces...

N

n!

Hiya,
One thing I used interfaces for when using C++ was defining lots of
header files for each interface being used, and allowing users to simply
#include the appropriate header file and use the interface immediately, no
linking required.

I had hoped that C# would allow me to do similar by defining the exact same
interface (namespace + contents) in multiple assemblies. As there are a few
assemblies I'd like to share the same interface, but be independant from
each other. I wrote a simple test for this, as I wasn't sure C# would like
it, by defining the interface in my executable and another assembly and
using a third assembly as a proxy to create an object instance. Meaning my
executable was not linked to the third assembly, but had an exact, matching
interface defined within it.

I seem to have confused it :( It compiles fine, and I even get a valid
object within my reference inside the executable. However as soon as I try
and call the interface I get an exception, this is something I was
expecting, but had hoped didn't happen :)

Anyway, to get to the root of my problem. The only way around this I can
think of is define an 'interface' assembly which contains only interfaces
and have all clients reference that. Not ideal but workable. So I was
wondering if anyone had any other thought before I decide on that.

thanks
n!
 
N

Nicholas Paldino [.NET/C# MVP]

n!,

Nope, that's exactly how you have to do it. Because the interface was
previously in another assembly, the type signature was completely different,
which caused the exception. This is good, IMO, because it forces you to
know the types you are working with, and there is no ambiguity (and less
bloat as well).

Hope this helps.
 
N

n!

Nope, that's exactly how you have to do it. Because the interface was
previously in another assembly, the type signature was completely different,
which caused the exception. This is good, IMO, because it forces you to
know the types you are working with, and there is no ambiguity (and less
bloat as well).

Thanks, the more I think about the more correct it seems. Versioning would
be a lot more hassle if you had the interface definition everywhere, with
them all in one place you can just release a new assembly version if an
interface gets updated.
 
S

Sput

I have not understood what are you trying to do so I'll tell you what I did.
I have a program which has only three forms and this program is at the same
time
accounting program, charter program, hotel management program, nautical
marina program,
auto-camp program (and can be anything else).
I have made this to avoid updating all programs when I find new, faster way
of doing something, or when I decide to update interface. To do this, I do
not use designer and all interfaces are created from a several parameters
(which define GUI as well as behavior, individual functions and other
specifics).
Also, this has enabled me to have only one .exe (which is currently around
300kb large) + one folder with graphical elements (around 1mb).
Which program will run is determined by available database tables.

Maybe this is out of the topic, maybe not.
However, I feel that this is the best way of programming bussiness
applications (all customers get same .exe and what will they use is defined
by options and given database - this also allows to have numerous ammount of
versions as each customer has different demands).
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top