Home All Groups Group Topic Archive Search About

How to override only Get or only Set?

Author
14 Jun 2006 11:44 AM
R. MacDonald
Hello, Group,

I have been curious about a statement I see occasionally in the VB
(v2003) help.  Sometimes the information about a property will indicate
that it is overridable, and I have been making use of this.  Sometimes
there is also a statement such as:

"You are not required to override both the get and set methods of the
.... property; you can override only one if needed."

Can anyone tell me how I can override just one of these?

So far, my practice has been to override the "entire" property, and
simply invoke the base property for the piece that I don't need to
adjust.  Is there a "better" way?

Cheers,
Randy

Author
14 Jun 2006 12:02 PM
Annie
why do you need to override only one of them?
any reasons?

Show quoteHide quote
"R. MacDonald" <sci***@NO-SP-AMcips.ca> wrote in message
news:448ff62e$0$82141$dbd41001@news.wanadoo.nl...
> Hello, Group,
>
> I have been curious about a statement I see occasionally in the VB (v2003)
> help.  Sometimes the information about a property will indicate that it is
> overridable, and I have been making use of this.  Sometimes there is also
> a statement such as:
>
> "You are not required to override both the get and set methods of the ...
> property; you can override only one if needed."
>
> Can anyone tell me how I can override just one of these?
>
> So far, my practice has been to override the "entire" property, and simply
> invoke the base property for the piece that I don't need to adjust.  Is
> there a "better" way?
>
> Cheers,
> Randy
>
Author
14 Jun 2006 1:21 PM
R. MacDonald
Hello, Annie,

There are several reasons why I might do this.  One example would be to
limit the Set property to a sub-set of possible values.  Sometimes I
will throw an exception, effectively making the Set property Read-Only
(or Write-once).  Sometimes it's only the behaviour of the Get that I
want to modify.

But invoking the base class property for the "other" half of a Get-Set
combination is pretty easy, so I don't really "need" to do it.  It's as
much a question of curiosity as it is wanting to save typing that one
short line.

Cheers,
Randy


Annie wrote:

Show quoteHide quote
> why do you need to override only one of them?
> any reasons?
>
> "R. MacDonald" <sci***@NO-SP-AMcips.ca> wrote in message
> news:448ff62e$0$82141$dbd41001@news.wanadoo.nl...
>
>>Hello, Group,
>>
>>I have been curious about a statement I see occasionally in the VB (v2003)
>>help.  Sometimes the information about a property will indicate that it is
>>overridable, and I have been making use of this.  Sometimes there is also
>>a statement such as:
>>
>>"You are not required to override both the get and set methods of the ...
>>property; you can override only one if needed."
>>
>>Can anyone tell me how I can override just one of these?
>>
>>So far, my practice has been to override the "entire" property, and simply
>>invoke the base property for the piece that I don't need to adjust.  Is
>>there a "better" way?
>>
>>Cheers,
>>Randy
>>
>
>
>
Author
14 Jun 2006 12:10 PM
CT
> So far, my practice has been to override the "entire" property, and simply
> invoke the base property for the piece that I don't need to adjust.

Well, that's how I do it too. :-) Well, at least in VB where I believe there
is no other way. It is possible in C# though, so perhaps the note is about
C# and possibly other .NET Framework dev languages?

--
Carsten Thomsen
Communities - http://community.integratedsolutions.dk
---------
Voodoo Programming: Things programmers do that they know shouldn't work but
they try anyway, and which sometimes actually work, such as recompiling
everything. (Karl Lehenbauer)
---------
Show quoteHide quote
"R. MacDonald" <sci***@NO-SP-AMcips.ca> wrote in message
news:448ff62e$0$82141$dbd41001@news.wanadoo.nl...
> Hello, Group,
>
> I have been curious about a statement I see occasionally in the VB (v2003)
> help.  Sometimes the information about a property will indicate that it is
> overridable, and I have been making use of this.  Sometimes there is also
> a statement such as:
>
> "You are not required to override both the get and set methods of the ...
> property; you can override only one if needed."
>
> Can anyone tell me how I can override just one of these?
>
> So far, my practice has been to override the "entire" property, and simply
> invoke the base property for the piece that I don't need to adjust.  Is
> there a "better" way?
>
> Cheers,
> Randy
>
Author
14 Jun 2006 1:23 PM
R. MacDonald
Hi, CT,

Thanks for your reply.  Yes, I imagine that you're correct, that the
note applies to other languages, but not to VB.  (Maybe in the future.)

Cheers,
Randy


CT wrote:

Show quoteHide quote
>>So far, my practice has been to override the "entire" property, and simply
>>invoke the base property for the piece that I don't need to adjust.
>
>
> Well, that's how I do it too. :-) Well, at least in VB where I believe there
> is no other way. It is possible in C# though, so perhaps the note is about
> C# and possibly other .NET Framework dev languages?
>