How to override only Get or only Set?

  • Thread starter Thread starter R. MacDonald
  • Start date Start date
R

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
 
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?
 
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
 
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
 
Back
Top