Re: Abstract class variables question
- From: Peter Duniho <NpOeStPeAdM@xxxxxxxxxxxxxxxx>
- Date: Thu, 15 Nov 2007 15:21:45 -0800
On 2007-11-15 13:45:12 -0800, "tshad" <tfs@xxxxxxxxxxxxxx> said:
[...]
No, they couldn't. The base class needs to know that this property
exists, because it uses it to validate the type when setting the data.
Without the abstract property, you couldn't write code in the base class
that relies on the property without having the base class be aware of each
and every derived class.
Which was what I was trying to figure out. And this is obviously the answer
as to how the Base Class can tell what the type is.
But I am confused as to how it works.
You actually set _TypeRequired in each class and _ValidateType seems to know
what _TypeRequired is. In _ValidateType, at the line:
Type typeRequired = _TypeRequired;
Before it is actually executed - it seems to know what _TypeRequired is !!!
That's probably just the debugger being clever. Nothing is actually known until the getter for the property is executed, which doesn't happen until that assignment is executed (or until the debugger tries to evaluate the property).
Yet I can't see where it is actually being set - just defined (either as
abstract or overridden).
I added a line just to break on and see what _TypeRequired is and it knew it
was system.bool. But where did it get set???
It's "set" basically as a hard-coded statement in the property declaration. There's no data storing the value; just a line of code that always returns the same value.
Because the property is "abstract", it's basically a virtual property, but without a default implementation (think pure virtual in C++). As a virtual property, the base class can call it without knowing the concrete type of the instance, and the override will still be executed and return the right value.
But the value per se isn't initialized or stored anywhere.
[...]
Just out of curiosity - I was wondering why you underscore _ValidateType and
_TypeRequired. I understand why you do it for _objCurrent (memory variable)
and why you use prefix the type (obj - hungarian). But I was wondering
about the other 2.
Actually, you don't understand why I do it for _objCurrent. :)
I am in the habit of using the underscore prefix for non-public members of classes. That's what you're seeing there. That applies both to _objCurrent field as well as methods and properties (like _ValidateType and _TypeRequired).
Pete
.
- Follow-Ups:
- Re: Abstract class variables question
- From: tshad
- Re: Abstract class variables question
- References:
- Abstract class variables question
- From: tshad
- Re: Abstract class variables question
- From: Peter Duniho
- Re: Abstract class variables question
- From: tshad
- Re: Abstract class variables question
- From: Peter Duniho
- Re: Abstract class variables question
- From: tshad
- Re: Abstract class variables question
- From: Peter Duniho
- Re: Abstract class variables question
- From: tshad
- Re: Abstract class variables question
- From: Peter Duniho
- Re: Abstract class variables question
- From: tshad
- Abstract class variables question
- Prev by Date: Re: General question on using Interfaces
- Next by Date: Re: Getting processes complete path correctly
- Previous by thread: Re: Abstract class variables question
- Next by thread: Re: Abstract class variables question
- Index(es):
Relevant Pages
|