473,796 Members | 2,603 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to override only Get or only Set?

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

Jun 14 '06 #1
4 1996
why do you need to override only one of them?
any reasons?

"R. MacDonald" <sc****@NO-SP-AMcips.ca> wrote in message
news:44******** *************** @news.wanadoo.n l...
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

Jun 14 '06 #2
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)
---------
"R. MacDonald" <sc****@NO-SP-AMcips.ca> wrote in message
news:44******** *************** @news.wanadoo.n l... 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

Jun 14 '06 #3
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:
why do you need to override only one of them?
any reasons?

"R. MacDonald" <sc****@NO-SP-AMcips.ca> wrote in message
news:44******** *************** @news.wanadoo.n l...
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


Jun 14 '06 #4
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:
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?

Jun 14 '06 #5

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

Similar topics

5
5919
by: Eric Johannsen | last post by:
I have a simple object that inherits from CollectionBase and overrides the Count property: namespace MyTest { public class CollTest : System.Collections.CollectionBase { public override int Count { get { return 0; }
14
12149
by: JPRoot | last post by:
Hi I use the following syntax to have events inherited from base to child classes which works nicely (virtual and override keyword on events). But I am wondering if it is a "supported" way of using events since I never saw it used anywhere in MSDN documentation/samples?! Or it will just break when I upgrade to .NET Framework 2.x in the coming years namespace MyNamespac public delegate void MyDel() public class MyBase public virtual...
8
2897
by: JPRoot | last post by:
Hi M. Jeffrey Tan, Just hopping you didn't forget me? :) Thanks JPRoot ----- \"Jeffrey Tan\" wrote: -----
5
6852
by: Darius | last post by:
I'm writing here in hopes that someone can explain the difference between the new and virtual/override keywords in C#. Specifically, what is the difference between this: public class Window { public void Draw() { Console.WriteLine("The WINDOW Draw method is running!");
4
2221
by: Jazper Manto | last post by:
hi what is the difference between virtual / override and new? until now i only knew the virtual / override thing. thanx for hint. Jazper //--- new ---------------------------------------- public class MyBaseA { public void Invoke() {}
7
6451
by: Dave Y | last post by:
I am a newbie to C# and am having trouble trying to override a ListView property method. I have created a new class derived from the Forms.Listview and I cannot figure out the syntax to override ListView.Items.Add(), . I see that it is a virtual method so it should be easy to do. If anyone can help I would appreciate it greatly. I can do what I need to do in a different way this would just make everything significantly cleaner and eaasier...
5
2615
by: Mark Broadbent | last post by:
Oh yes its that chestnut again! Ive gone over the following (http://www.yoda.arachsys.com/csharp/faq/ -thanks Jon!) again regarding this subject and performed a few of my own tests. I have two classes yClass which inherits xClass. xClass has a virtual method which simply writes a line of text stating its origin, yClass implements the same method which writes a line of text stating its origin also (i.e. "From yClass"). I ran the...
5
4536
by: Marcel Hug | last post by:
Hi NG ! I'm new in C# and I'm reading a book about the fundamentals and concepts. In the chapter Methods it's written to use virtual, if i would like to override the method in a subclass. This I've to do by using override. It's also written, that's possible to "hide" the base class method by using the new key word. Because I've already written some C# code and I didn't know anything
9
1797
by: Ben Voigt | last post by:
Found another variation on my previous bug (https://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?FeedbackID=100917) I would welcome validation and votes. class ISkewEstimator {
0
9685
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10465
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10242
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
10021
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9061
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6800
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
4127
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 we have to send another system
2
3744
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2931
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.