473,394 Members | 2,052 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

Multiple matching interfaces...

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!
Nov 15 '05 #1
3 1205
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.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"n!" <nf********@nomailplease.com> wrote in message
news:ep**************@TK2MSFTNGP09.phx.gbl...
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!

Nov 15 '05 #2
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.
Nov 15 '05 #3
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).


Nov 15 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: Hung Jung Lu | last post by:
Hi, I think Microsoft did look into Python when they designed C#. (E.g. they got rid of checked exceptions of Java.) However, they followed Java in avoiding multiple inheritance (MI), which is a...
8
by: Shawn Casey | last post by:
Consider the following code: interface IBase { virtual void BaseFunction() = 0; }; interface IDerived : public IBase { virtual void DerivedFunction() = 0;
6
by: Paul | last post by:
In real life situation, do we ever come across a situation where we would need two base objects in an object. A snippet is worth 1000 words (: so... class Base { }; class Derived1:public Base...
22
by: Matthew Louden | last post by:
I want to know why C# doesnt support multiple inheritance? But why we can inherit multiple interfaces instead? I know this is the rule, but I dont understand why. Can anyone give me some concrete...
47
by: Larry Smith | last post by:
I just read a blurb in MSDN under the C++ "ref" keyword which states that: "Under the CLR object model, only public single inheritance is supported". Does this mean that no .NET class can ever...
7
by: Mukesh | last post by:
Hi, Consider a situation where a class (Say C1) is implementing two interfaces (I1, I2). Both the interface contains a method (M1) with the same signature. class C1:I1, I2 { //implementation...
18
by: GD | last post by:
Please remove ability to multiple inheritance in Python 3000. Multiple inheritance is bad for design, rarely used and contains many problems for usual users. Every program can be designed only...
0
by: Peter | last post by:
Hi I'm stuck and would appreciate some help. I have created a Class library project that contains a number of interface definitions that must be used by a range of other VB.NET applications. ...
3
by: johanatan | last post by:
When I first heard about these new features, I was very excited as it would have (if implemented as I had expected) rendered mimicking multiple inheritance almost painless in C#. Unfortunately,...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.