473,396 Members | 1,997 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,396 software developers and data experts.

How to make derived interface property read-only ?

I have one interface "Intf1" with read-write property "Prop" (with "get" and
"set" accessors).

Then I declare derived interface "Intf2" with the same property "Prop"
declared as read-only (without "set" accessor).
Property "Prop" in derived interface "Intf2" is marked with "new" modifier.

Then I implement derived interface "Intf2" in class "Clss2" with read-only
property "Prop" (without "set" accessor).
Property "Prop" in class "Clss2" is marked with "new" modifier.

During compilation I get the following error:

*******************
Clss2 does not implement interface member 'Intf1.Prop.set'
*******************

but property "Prop" is declared in interface "Intf2" and is read-only.

What's wrong ?
Oleg Subachev
Aug 31 '06 #1
2 3150
Oleg,

Since Intf2 inherits Intf1 then Clss2 must implement everything in
Intf1 and Intf2. Now, because you've hidden a member declaration in
Intf2 using the 'new' keyword here's what you'll see happen.

Clss2 foo = new Clss2();
foo.Prop = 5; // ok

Intf1 foo = new Clss2();
foo.Prop = 5; // ok

Intf2 foo = new Clss2();
foo.Prop = 5; // compile error

Brian

Oleg Subachev wrote:
I have one interface "Intf1" with read-write property "Prop" (with "get" and
"set" accessors).

Then I declare derived interface "Intf2" with the same property "Prop"
declared as read-only (without "set" accessor).
Property "Prop" in derived interface "Intf2" is marked with "new" modifier.

Then I implement derived interface "Intf2" in class "Clss2" with read-only
property "Prop" (without "set" accessor).
Property "Prop" in class "Clss2" is marked with "new" modifier.

During compilation I get the following error:

*******************
Clss2 does not implement interface member 'Intf1.Prop.set'
*******************

but property "Prop" is declared in interface "Intf2" and is read-only.

What's wrong ?
Oleg Subachev
Aug 31 '06 #2
Oleg Subachev <ol**@urvb.ruwrote:
I have one interface "Intf1" with read-write property "Prop" (with "get" and
"set" accessors).

Then I declare derived interface "Intf2" with the same property "Prop"
declared as read-only (without "set" accessor).
Property "Prop" in derived interface "Intf2" is marked with "new" modifier.

Then I implement derived interface "Intf2" in class "Clss2" with read-only
property "Prop" (without "set" accessor).
Property "Prop" in class "Clss2" is marked with "new" modifier.

During compilation I get the following error:

*******************
Clss2 does not implement interface member 'Intf1.Prop.set'
*******************

but property "Prop" is declared in interface "Intf2" and is read-only.

What's wrong ?
Well, you've declared that the class implements the first interface
(because the second interface derives from the first). The first
interface has a setter, therefore to implement the interface fully you
need a setter.

You can't use inheritance to "remove" members from an interface.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
Sep 5 '06 #3

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

Similar topics

7
by: Baski | last post by:
Base class: class AssetBase { string _clli; public string CLLI { get
6
by: John Salerno | last post by:
I understand how they work (basically), but I think maybe the examples I'm reading are too elementary to really show their value. Here's one from Programming C#: #region Using directives ...
2
by: 0to60 | last post by:
I have a base class that defines a property. I'd like the the Get to be implemented by the base class and not overrideable. I would like the Set to be marked abstract, and thus needs to be filled...
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...
3
by: Roy | last post by:
If I have two interfaces derived from the same one. How do I implement the methods in my class supporting both interfaces? I would like to have different implementation for methods in base...
9
by: hufaunder | last post by:
I have a class "TestSuper" that implements the interface "TestBase". The interface has a property of type "ReturnType". The class "TestSuper" does not return "ReturnType" but a derivation...
4
by: developereo | last post by:
Hi folks, Can anybody shed some light on this problem? class Interface { public: Interface() { ...} virtual ~Interface() { ...} virtual method() = 0; };
3
by: rep_movsd | last post by:
Hi I have a C++ com object that exposes IStream and IPropertyBag, this is derived from IUnknown, there is no typelib or IDispatch etc I need to write a simple VB.NET app in VB 2003 that can...
5
by: Lothar Behrens | last post by:
Hi, I have created a base class implementing an interface and a derived class also implementing the same interface. While figuring out that I am unable to call the derived method of an instance...
2
by: SimonDotException | last post by:
I am trying to use reflection in a property of a base type to inspect the properties of an instance of a type which is derived from that base type, when the properties can themselves be instances of...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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
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...

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.