473,405 Members | 2,262 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,405 software developers and data experts.

Properties of Interfaces

Could someone clarify why this doesn't work? Is there a persuasive reason
why it shouldn't?

interface IGetOnly {
string Name { get; }
}

interface IGetAndSet : IGetOnly {
string Name { set; }
}

It should be clear what I want to do here: extend the interface IGetOnly
with a setter. I know that the getter is implemented as get_Name, but I then
have a class that implements IGetAndSet, it does *not* have a getter. If I
add a getter to the second interface declaration, I have a conflict over
"Name", which I have to resolve by using "new." But the getter isn't new! I
can declare get_Name and set_Name directly, but that doesn't work (I'll
spare the readers the details).
Nov 15 '05 #1
6 1431
I can verify that I too have run into something very similar (and I wouldn't
be surprised if it's the same underlying cause) but I can't really give you
a good reason why it's this way. It's likely there is either a good reason
or it's simply the by-product of the implementation.

My guess is that it's something along the lines of a signature for the
properties is created in the base interface and the derived interface is
breaking that signature.

Sorry, not much help, am I?

Pete

--
http://www.petedavis.net

"Tony Nassar" <tn*****@theanalysiscorp.com> wrote in message
news:%2****************@tk2msftngp13.phx.gbl...
Could someone clarify why this doesn't work? Is there a persuasive reason
why it shouldn't?

interface IGetOnly {
string Name { get; }
}

interface IGetAndSet : IGetOnly {
string Name { set; }
}

It should be clear what I want to do here: extend the interface IGetOnly
with a setter. I know that the getter is implemented as get_Name, but I then have a class that implements IGetAndSet, it does *not* have a getter. If I
add a getter to the second interface declaration, I have a conflict over
"Name", which I have to resolve by using "new." But the getter isn't new! I can declare get_Name and set_Name directly, but that doesn't work (I'll
spare the readers the details).

Nov 15 '05 #2
Tony,
In Interface extensions, we may add more methods and even new property
skeletons, but we cannot mask off (override) an existing function and
replace it with extra functionality.
We want to achieve:
interface IGetAndSet {
string Name{get;set;}
}
The intention of having "Name{get;}" member now changed to "Name{get;set;}"
is not exactly and extention, but a signature replacement of existing
Interface member.
Thanks,
Fakher Halim

"Pete Davis" <pd******@hotmail.com> wrote in message
news:0e******************************@news.meganet news.com...
I can verify that I too have run into something very similar (and I wouldn't be surprised if it's the same underlying cause) but I can't really give you a good reason why it's this way. It's likely there is either a good reason
or it's simply the by-product of the implementation.

My guess is that it's something along the lines of a signature for the
properties is created in the base interface and the derived interface is
breaking that signature.

Sorry, not much help, am I?

Pete

--
http://www.petedavis.net

"Tony Nassar" <tn*****@theanalysiscorp.com> wrote in message
news:%2****************@tk2msftngp13.phx.gbl...
Could someone clarify why this doesn't work? Is there a persuasive reason why it shouldn't?

interface IGetOnly {
string Name { get; }
}

interface IGetAndSet : IGetOnly {
string Name { set; }
}

It should be clear what I want to do here: extend the interface IGetOnly
with a setter. I know that the getter is implemented as get_Name, but I then
have a class that implements IGetAndSet, it does *not* have a getter. If I add a getter to the second interface declaration, I have a conflict over
"Name", which I have to resolve by using "new." But the getter isn't

new! I
can declare get_Name and set_Name directly, but that doesn't work (I'll
spare the readers the details).


Nov 15 '05 #3
I find this explanation completely unpersuasive; it merely reiterates what
the compiler told me. We all know that the "Name" property becomes
get_Name() in the IL; extending the interface with set_Name() would be no
problem IF THE LANGUAGE DESIGNERS HAD ALLOWED IT.
The intention of having "Name{get;}" member now changed to "Name{get;set;}" is not exactly an extention, but a signature replacement of existing
Interface member.
Thanks,
Fakher Halim

Nov 15 '05 #4
Tony,

I think this is by design and correct. What the get_XXX in the IL really
means is "read-only." So, the OO theory says that you wouldn't want derived
classes to alter the semantics of the read-only XXX property, right?

The get_ and put_ methods are just implementation details that express in IL
what the design intent (read-only) is, right? So, if the designer intended
read-only, you wouldn't want to allow derived classes to override that
intent, right?

In your case, I think requiring the "new" keyword is correct, because the
base classes, already being written--possibly by someone else--don't know
anything about the new semantics you want to give the already existing XXX
property.

Hope this helps/makes sense,

-Jason

"Tony Nassar" <tn*****@theanalysiscorp.com> wrote in message
news:eE**************@TK2MSFTNGP11.phx.gbl...
I find this explanation completely unpersuasive; it merely reiterates what
the compiler told me. We all know that the "Name" property becomes
get_Name() in the IL; extending the interface with set_Name() would be no
problem IF THE LANGUAGE DESIGNERS HAD ALLOWED IT.
The intention of having "Name{get;}" member now changed to

"Name{get;set;}"
is not exactly an extention, but a signature replacement of existing
Interface member.
Thanks,
Fakher Halim


Nov 15 '05 #5
That *is* persuasive; thank you.

Tony

"Mailing Lists" <ml******@berkea.com> wrote in message
news:eF**************@TK2MSFTNGP10.phx.gbl...
Tony,

I think this is by design and correct. What the get_XXX in the IL really
means is "read-only." So, the OO theory says that you wouldn't want derived classes to alter the semantics of the read-only XXX property, right?

The get_ and put_ methods are just implementation details that express in IL what the design intent (read-only) is, right? So, if the designer intended read-only, you wouldn't want to allow derived classes to override that
intent, right?

In your case, I think requiring the "new" keyword is correct, because the
base classes, already being written--possibly by someone else--don't know
anything about the new semantics you want to give the already existing XXX
property.

Hope this helps/makes sense,

-Jason

"Tony Nassar" <tn*****@theanalysiscorp.com> wrote in message
news:eE**************@TK2MSFTNGP11.phx.gbl...
I find this explanation completely unpersuasive; it merely reiterates what the compiler told me. We all know that the "Name" property becomes
get_Name() in the IL; extending the interface with set_Name() would be no problem IF THE LANGUAGE DESIGNERS HAD ALLOWED IT.
The intention of having "Name{get;}" member now changed to

"Name{get;set;}"
is not exactly an extention, but a signature replacement of existing
Interface member.
Thanks,
Fakher Halim



Nov 15 '05 #6
Wait a minute, that's not correct. If get_Name() returns a reference to an
object of reference type, then it is not a read-only reference. Compare

interface IReadOnly {
IList MyList { get; }
}

The return value is in no sense "read-only." It's not a C++-style reference
to const. I cannot overwrite the object's reference to an IList (that would
require a setter), but I can insert into and delete from the object's IList
to my heart's content. Unless of course the object implementing IReadOnly
copies the array, etc., etc., but that's an implementation detail
independent of the interface contract.

Tony

I think this is by design and correct. What the get_XXX in the IL really
means is "read-only." So, the OO theory says that you wouldn't want derived classes to alter the semantics of the read-only XXX property, right?

The get_ and put_ methods are just implementation details that express in IL what the design intent (read-only) is, right? So, if the designer intended read-only, you wouldn't want to allow derived classes to override that
intent, right?

In your case, I think requiring the "new" keyword is correct, because the
base classes, already being written--possibly by someone else--don't know
anything about the new semantics you want to give the already existing XXX
property.

Hope this helps/makes sense,

-Jason

"Tony Nassar" <tn*****@theanalysiscorp.com> wrote in message
news:eE**************@TK2MSFTNGP11.phx.gbl...
I find this explanation completely unpersuasive; it merely reiterates what the compiler told me. We all know that the "Name" property becomes
get_Name() in the IL; extending the interface with set_Name() would be no problem IF THE LANGUAGE DESIGNERS HAD ALLOWED IT.
The intention of having "Name{get;}" member now changed to

"Name{get;set;}"
is not exactly an extention, but a signature replacement of existing
Interface member.
Thanks,
Fakher Halim



Nov 15 '05 #7

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

Similar topics

4
by: iceColdFire | last post by:
Hi, Scenario is that I have a lib where I am using its class Robot to create my own objects.. Now here comes the trouble part...I dont have its API... I used dumpbin \exports but could not...
2
by: Paul Selormey | last post by:
I have looked through the documents but could not find any information on this. Is anything like static properties in interfaces? If not, how do I define property in interface to be made static...
6
by: ~~~ .NET Ed ~~~ | last post by:
Yes, I think so at least... In C# you *can* have static properties which are quite useful when used properly. Now imagine the scenario where you need the ability (sp?) to implement a variety of...
4
by: Craig | last post by:
I'm trying to build a filter for a file search where the search will be able to filter out certain files according to certain "file properties", like Owner, Creation Date, etc. MS does this in...
3
by: Julia | last post by:
Hi, In general my question is how can I set properties on a concrete class while programming against interfaces For example I have a MailServerFatory which can create two types of Mail...
10
by: Jeff Grills | last post by:
I am an experienced C++ programmer with over 12 years of development, and I think I know C++ quite well. I'm changing jobs at the moment, and I have about a month between leaving my last job and...
0
by: darrel | last post by:
Thanks to some help from Karl yesterday, I've discovered the use of Interfaces to allow usercontrols to communicate information between them using the Interface as the 'parent' rather than the aspx...
2
by: ABC | last post by:
I am always to write clases which has properties, is here any best tools or method let me typing properties codes more fast?
3
by: cwertman | last post by:
I have a question regarding dynamic properties. I have an Object say Account --Id --Prefix --Fname --Lname --Suffix
3
by: William Youngman | last post by:
I am on a team that is developing a proposal generation web application and we are using a custom base page (ProGenBase.cs) located in the app_code directory and all of the app's web pages inherit...
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
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
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,...

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.