473,463 Members | 1,380 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

interface, implementation, and visibility

Hello,

I'm trying to create a component that will be used from .net clients and COM
clients. I've got an object model that looks something like this:

ISystem
IRuntime
IConfiguration
ICollectionOfConfigurableThings
IConfigurableThing

I've created a C# project (starting with the ClassLibrary selection) and
have declared the interfaces, and classes that implement the interfaces.
However, when I want to test the component in a client (in this case, C#)
both the interfaces and the classes are visible. This doesn't seem correct -
a bit too confusing for the users of the object model. What's the correct
way to do this - any good samples out there?

I'd like the client application to be able to do the follow:

ISystem s = new ISystem();
IConfiguration c = s.Configuration;
IConfigurableThing t = c.CreateConfigurableThing("name", "type");
t.SomeProperty = "x";
c.ICollectionOfConfigurableThings.Add(t);

Thanks,
Ken
May 23 '06 #1
8 1456
khalprin wrote:
Hello,

I'm trying to create a component that will be used from .net clients and COM
clients. I've got an object model that looks something like this:

ISystem
IRuntime
IConfiguration
ICollectionOfConfigurableThings
IConfigurableThing

I've created a C# project (starting with the ClassLibrary selection) and
have declared the interfaces, and classes that implement the interfaces.
However, when I want to test the component in a client (in this case, C#)
both the interfaces and the classes are visible. This doesn't seem correct -
a bit too confusing for the users of the object model. What's the correct
way to do this - any good samples out there?

I'd like the client application to be able to do the follow:

ISystem s = new ISystem();
That is not possible. You can't create instances of an interface.
IConfiguration c = s.Configuration;
IConfigurableThing t = c.CreateConfigurableThing("name", "type");
t.SomeProperty = "x";
As you only access those objects through interfaces, the actual classes
doesn't have to be accessible. You can make those classes private.
c.ICollectionOfConfigurableThings.Add(t);
An interface is not a property of the object. If the object contains a
collection that implements that interface, you have to expose the
collection through a property.

Thanks,
Ken

May 23 '06 #2
Goran,

Thanks for the reply.

I understand your statements, I guess I wasn't very careful when describing
the way the client app would use the component - it was mostly just to show
the steps involved in using the different objects. My question is what kind
of visibility the interface and class declarations should have. I don't want
the client apps to see both classes and the interfaces.

Should I make both the interface and the class public, as below? This is
the way I originally worked it, but the client app can see the ISystem
interface and the System class, as well as the IConfiguration interface and
the Configuration class.

When I make one or the other 'not public', I run in to errors that state the
level of access conflicts between the classes and interfaces.

public interface IConfiguration
{
....
}

public class Configuration : IConfiguration
{
....
}

public interface ISystem
{
IConfiguration Configuration { get; }
}

public class System : ISystem
{
private Configuration m_Configuration = new Configuration();
public IConfiguration Configuration
{
get { return m_Configuration; }
}
}

Ken
"Göran Andersson" wrote:
khalprin wrote:
Hello,

I'm trying to create a component that will be used from .net clients and COM
clients. I've got an object model that looks something like this:

ISystem
IRuntime
IConfiguration
ICollectionOfConfigurableThings
IConfigurableThing

I've created a C# project (starting with the ClassLibrary selection) and
have declared the interfaces, and classes that implement the interfaces.
However, when I want to test the component in a client (in this case, C#)
both the interfaces and the classes are visible. This doesn't seem correct -
a bit too confusing for the users of the object model. What's the correct
way to do this - any good samples out there?

I'd like the client application to be able to do the follow:

ISystem s = new ISystem();


That is not possible. You can't create instances of an interface.
IConfiguration c = s.Configuration;
IConfigurableThing t = c.CreateConfigurableThing("name", "type");
t.SomeProperty = "x";


As you only access those objects through interfaces, the actual classes
doesn't have to be accessible. You can make those classes private.
c.ICollectionOfConfigurableThings.Add(t);


An interface is not a property of the object. If the object contains a
collection that implements that interface, you have to expose the
collection through a property.

Thanks,
Ken

May 23 '06 #3
It looks like you are using interfaces where nested members could work
better (if the confusion came from the COM world, just start fresh with .NET
where classes are first class citizens).

An interface can be usefull to see an object under multiple personalities
(for example the IComparable interface allows to define how objects of a
given type should be compared, is is not related at all to the real purpose
of this object and is not seen unless explicitelty required).

Here I would just use regular classes :
MySystem s=new MySystem();
Property p=s.Configuration.Add("type","name");
p.Value="x";
etc...

--

"khalprin" <kh******@discussions.microsoft.com> a écrit dans le message de
news: F6**********************************@microsoft.com...
Hello,

I'm trying to create a component that will be used from .net clients and
COM
clients. I've got an object model that looks something like this:

ISystem
IRuntime
IConfiguration
ICollectionOfConfigurableThings
IConfigurableThing

I've created a C# project (starting with the ClassLibrary selection) and
have declared the interfaces, and classes that implement the interfaces.
However, when I want to test the component in a client (in this case, C#)
both the interfaces and the classes are visible. This doesn't seem
correct -
a bit too confusing for the users of the object model. What's the correct
way to do this - any good samples out there?

I'd like the client application to be able to do the follow:

ISystem s = new ISystem();
IConfiguration c = s.Configuration;
IConfigurableThing t = c.CreateConfigurableThing("name", "type");
t.SomeProperty = "x";
c.ICollectionOfConfigurableThings.Add(t);

Thanks,
Ken

May 23 '06 #4
What, no interfaces! I'll try that to see how it works. In that case, do I
just mark the classes as '[ComVisible(true)]'
Ken

"Patrice" wrote:
It looks like you are using interfaces where nested members could work
better (if the confusion came from the COM world, just start fresh with .NET
where classes are first class citizens).

An interface can be usefull to see an object under multiple personalities
(for example the IComparable interface allows to define how objects of a
given type should be compared, is is not related at all to the real purpose
of this object and is not seen unless explicitelty required).

Here I would just use regular classes :
MySystem s=new MySystem();
Property p=s.Configuration.Add("type","name");
p.Value="x";
etc...

--

"khalprin" <kh******@discussions.microsoft.com> a écrit dans le message de
news: F6**********************************@microsoft.com...
Hello,

I'm trying to create a component that will be used from .net clients and
COM
clients. I've got an object model that looks something like this:

ISystem
IRuntime
IConfiguration
ICollectionOfConfigurableThings
IConfigurableThing

I've created a C# project (starting with the ClassLibrary selection) and
have declared the interfaces, and classes that implement the interfaces.
However, when I want to test the component in a client (in this case, C#)
both the interfaces and the classes are visible. This doesn't seem
correct -
a bit too confusing for the users of the object model. What's the correct
way to do this - any good samples out there?

I'd like the client application to be able to do the follow:

ISystem s = new ISystem();
IConfiguration c = s.Configuration;
IConfigurableThing t = c.CreateConfigurableThing("name", "type");
t.SomeProperty = "x";
c.ICollectionOfConfigurableThings.Add(t);

Thanks,
Ken


May 23 '06 #5
Just create your .NET class and use the regasm tool (the needed COM
interface is created for you by this tool). They are visible by default (you
can mark just those you don't want to expose).

For now it looks like to me you are creating interfaces either thinking this
..NET is similar to COM or thinking that they are needed for COM interop...
Or do you create those interfaces for some other purpose ?

--
Patrice

"khalprin" <kh******@discussions.microsoft.com> a écrit dans le message de
news: 26**********************************@microsoft.com...
What, no interfaces! I'll try that to see how it works. In that case, do
I
just mark the classes as '[ComVisible(true)]'
Ken

"Patrice" wrote:
It looks like you are using interfaces where nested members could work
better (if the confusion came from the COM world, just start fresh with
.NET
where classes are first class citizens).

An interface can be usefull to see an object under multiple personalities
(for example the IComparable interface allows to define how objects of a
given type should be compared, is is not related at all to the real
purpose
of this object and is not seen unless explicitelty required).

Here I would just use regular classes :
MySystem s=new MySystem();
Property p=s.Configuration.Add("type","name");
p.Value="x";
etc...

--

"khalprin" <kh******@discussions.microsoft.com> a écrit dans le message
de
news: F6**********************************@microsoft.com...
> Hello,
>
> I'm trying to create a component that will be used from .net clients
> and
> COM
> clients. I've got an object model that looks something like this:
>
> ISystem
> IRuntime
> IConfiguration
> ICollectionOfConfigurableThings
> IConfigurableThing
>
> I've created a C# project (starting with the ClassLibrary selection)
> and
> have declared the interfaces, and classes that implement the
> interfaces.
> However, when I want to test the component in a client (in this case,
> C#)
> both the interfaces and the classes are visible. This doesn't seem
> correct -
> a bit too confusing for the users of the object model. What's the
> correct
> way to do this - any good samples out there?
>
> I'd like the client application to be able to do the follow:
>
> ISystem s = new ISystem();
> IConfiguration c = s.Configuration;
> IConfigurableThing t = c.CreateConfigurableThing("name", "type");
> t.SomeProperty = "x";
> c.ICollectionOfConfigurableThings.Add(t);
>
> Thanks,
> Ken
>
>


May 23 '06 #6
I was creating them because I thought they were needed for COM interop, and
also because it forces me to think of them as immutable - it's too easy to
change the members and method parameters of a class, but I think a lot harder
when it's an interface.

One thing I'm still not really clear on is the visibility of the class
members. When using the component in a .NET client app, all the class
members are visible, whether they're part of the 'interface' or not. How is
that normally handled? I don't want the client apps to see everything behind
the 'interface' (sorry, that's the only word I can think of to describe the
demarcation).

There's gotta be a sample that shows how this is normally done...

Thanks for your input.

"Patrice" wrote:
Just create your .NET class and use the regasm tool (the needed COM
interface is created for you by this tool). They are visible by default (you
can mark just those you don't want to expose).

For now it looks like to me you are creating interfaces either thinking this
..NET is similar to COM or thinking that they are needed for COM interop...
Or do you create those interfaces for some other purpose ?

--
Patrice

"khalprin" <kh******@discussions.microsoft.com> a écrit dans le message de
news: 26**********************************@microsoft.com...
What, no interfaces! I'll try that to see how it works. In that case, do
I
just mark the classes as '[ComVisible(true)]'
Ken

"Patrice" wrote:
It looks like you are using interfaces where nested members could work
better (if the confusion came from the COM world, just start fresh with
.NET
where classes are first class citizens).

An interface can be usefull to see an object under multiple personalities
(for example the IComparable interface allows to define how objects of a
given type should be compared, is is not related at all to the real
purpose
of this object and is not seen unless explicitelty required).

Here I would just use regular classes :
MySystem s=new MySystem();
Property p=s.Configuration.Add("type","name");
p.Value="x";
etc...

--

"khalprin" <kh******@discussions.microsoft.com> a écrit dans le message
de
news: F6**********************************@microsoft.com...
> Hello,
>
> I'm trying to create a component that will be used from .net clients
> and
> COM
> clients. I've got an object model that looks something like this:
>
> ISystem
> IRuntime
> IConfiguration
> ICollectionOfConfigurableThings
> IConfigurableThing
>
> I've created a C# project (starting with the ClassLibrary selection)
> and
> have declared the interfaces, and classes that implement the
> interfaces.
> However, when I want to test the component in a client (in this case,
> C#)
> both the interfaces and the classes are visible. This doesn't seem
> correct -
> a bit too confusing for the users of the object model. What's the
> correct
> way to do this - any good samples out there?
>
> I'd like the client application to be able to do the follow:
>
> ISystem s = new ISystem();
> IConfiguration c = s.Configuration;
> IConfigurableThing t = c.CreateConfigurableThing("name", "type");
> t.SomeProperty = "x";
> c.ICollectionOfConfigurableThings.Add(t);
>
> Thanks,
> Ken
>
>


May 23 '06 #7
This is not needed. The tool does this for you (afaik it creates a
_classname interface).

Visibility rules are here :
http://msdn.microsoft.com/library/de...roperation.asp

Note that AFAIK :
- private members are not exposed
- you can use the ComVisible attribute to hide a public member from COM

Remember laso that .NET has also some different options for versioning
(putting this in the GAC may help handle this).

Though articles such as :
http://msdn.microsoft.com/library/de...amewktools.asp
recommend creating explicitly the interface, you may still want to try the
simpler approach for now to see if it fits your needs (as a side note the
article likely uses the ClassInterface attribute you are likely missing from
your current code).

Good luck. Hope it helps.

--
Patrice

"khalprin" <kh******@discussions.microsoft.com> a écrit dans le message de
news: ED**********************************@microsoft.com...
I was creating them because I thought they were needed for COM interop, and
also because it forces me to think of them as immutable - it's too easy to
change the members and method parameters of a class, but I think a lot
harder
when it's an interface.

One thing I'm still not really clear on is the visibility of the class
members. When using the component in a .NET client app, all the class
members are visible, whether they're part of the 'interface' or not. How
is
that normally handled? I don't want the client apps to see everything
behind
the 'interface' (sorry, that's the only word I can think of to describe
the
demarcation).

There's gotta be a sample that shows how this is normally done...

Thanks for your input.

"Patrice" wrote:
Just create your .NET class and use the regasm tool (the needed COM
interface is created for you by this tool). They are visible by default
(you
can mark just those you don't want to expose).

For now it looks like to me you are creating interfaces either thinking
this
..NET is similar to COM or thinking that they are needed for COM
interop...
Or do you create those interfaces for some other purpose ?

--
Patrice

"khalprin" <kh******@discussions.microsoft.com> a écrit dans le message
de
news: 26**********************************@microsoft.com...
> What, no interfaces! I'll try that to see how it works. In that case,
> do
> I
> just mark the classes as '[ComVisible(true)]'
> Ken
>
> "Patrice" wrote:
>
>> It looks like you are using interfaces where nested members could work
>> better (if the confusion came from the COM world, just start fresh
>> with
>> .NET
>> where classes are first class citizens).
>>
>> An interface can be usefull to see an object under multiple
>> personalities
>> (for example the IComparable interface allows to define how objects of
>> a
>> given type should be compared, is is not related at all to the real
>> purpose
>> of this object and is not seen unless explicitelty required).
>>
>> Here I would just use regular classes :
>> MySystem s=new MySystem();
>> Property p=s.Configuration.Add("type","name");
>> p.Value="x";
>> etc...
>>
>> --
>>
>> "khalprin" <kh******@discussions.microsoft.com> a écrit dans le
>> message
>> de
>> news: F6**********************************@microsoft.com...
>> > Hello,
>> >
>> > I'm trying to create a component that will be used from .net clients
>> > and
>> > COM
>> > clients. I've got an object model that looks something like this:
>> >
>> > ISystem
>> > IRuntime
>> > IConfiguration
>> > ICollectionOfConfigurableThings
>> > IConfigurableThing
>> >
>> > I've created a C# project (starting with the ClassLibrary selection)
>> > and
>> > have declared the interfaces, and classes that implement the
>> > interfaces.
>> > However, when I want to test the component in a client (in this
>> > case,
>> > C#)
>> > both the interfaces and the classes are visible. This doesn't seem
>> > correct -
>> > a bit too confusing for the users of the object model. What's the
>> > correct
>> > way to do this - any good samples out there?
>> >
>> > I'd like the client application to be able to do the follow:
>> >
>> > ISystem s = new ISystem();
>> > IConfiguration c = s.Configuration;
>> > IConfigurableThing t = c.CreateConfigurableThing("name", "type");
>> > t.SomeProperty = "x";
>> > c.ICollectionOfConfigurableThings.Add(t);
>> >
>> > Thanks,
>> > Ken
>> >
>> >
>>
>>
>>


May 23 '06 #8
Aha, so there's the problem. I thought that you had any well founded
reason for wanting the interfaces. ;)

No, you don't need any interfaces at all. Yes, the ComVisible attribute
should do it.

khalprin wrote:
What, no interfaces! I'll try that to see how it works. In that case, do I
just mark the classes as '[ComVisible(true)]'
Ken

"Patrice" wrote:
It looks like you are using interfaces where nested members could work
better (if the confusion came from the COM world, just start fresh with .NET
where classes are first class citizens).

An interface can be usefull to see an object under multiple personalities
(for example the IComparable interface allows to define how objects of a
given type should be compared, is is not related at all to the real purpose
of this object and is not seen unless explicitelty required).

Here I would just use regular classes :
MySystem s=new MySystem();
Property p=s.Configuration.Add("type","name");
p.Value="x";
etc...

--

"khalprin" <kh******@discussions.microsoft.com> a écrit dans le message de
news: F6**********************************@microsoft.com...
Hello,

I'm trying to create a component that will be used from .net clients and
COM
clients. I've got an object model that looks something like this:

ISystem
IRuntime
IConfiguration
ICollectionOfConfigurableThings
IConfigurableThing

I've created a C# project (starting with the ClassLibrary selection) and
have declared the interfaces, and classes that implement the interfaces.
However, when I want to test the component in a client (in this case, C#)
both the interfaces and the classes are visible. This doesn't seem
correct -
a bit too confusing for the users of the object model. What's the correct
way to do this - any good samples out there?

I'd like the client application to be able to do the follow:

ISystem s = new ISystem();
IConfiguration c = s.Configuration;
IConfigurableThing t = c.CreateConfigurableThing("name", "type");
t.SomeProperty = "x";
c.ICollectionOfConfigurableThings.Add(t);

Thanks,
Ken


May 23 '06 #9

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

Similar topics

9
by: Vladimir Bezugliy | last post by:
I have next interface: interface I { void F(); } And next class implements this interface: class MyClass : I { void F(){};
5
by: Mark | last post by:
Below I've created an interface ... why do all implementations of the methods have to be public? What if I want them to be private or protected? public interface IOisWebPageStandard { void...
3
by: John Underwood | last post by:
Hi.. I was looking at interface, and I have a example in the docs i'll paste below.. I'm not grasping what you would gain by using a interface, does any one have a brief description of their...
5
by: Keith Patrick | last post by:
Could someone tell me if it's possible (and if so, how) to call an explicitly-implemented interface method from a subclass? I have a class in which I have to explicity implement some methods, but...
8
by: Bill Rust | last post by:
I've created an "Add Item" wizard for VB.NET 2003 that allows a user to add a specialized class that works with my application framework. In the wizard, the user can select the interfaces they...
12
by: masoud bayan | last post by:
I've come across something in Interface implementation that I am not sure is correct behavior in VB.NET (and maybe C#) or not? Consider following example: Public Interface IShape
52
by: Ben Voigt [C++ MVP] | last post by:
I get C:\Programming\LTM\devtools\UselessJunkForDissassembly\Class1.cs(360,27): error CS0535: 'UselessJunkForDissassembly.InvocableInternals' does not implement interface member...
4
by: ~~~ .NET Ed ~~~ | last post by:
I am facing a problem. My project is composed of several assemblies. In one of them -the backend- I have several internal classes that must implement an interface. These internal classes are only...
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
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
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
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...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
1
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

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.