E
Edward Diener
Is it possible for a derived class to override a property and/or event of
its base class ?
its base class ?
Scott said:Only if the base class has that item marked as overrideable. If not,
you'll need to use Shadows.
Yes, Shadows is a VB term. Its called a "new" member in C# and I dunno aboutEdward Diener said:I assume when you say Shadows you mean that the derived class creates a
property or event with the same name as the base class and calls down to
the
base class as needed.
For C# and C++, the declaration should be marked virtual or abstract, whileWhat in the documentation tells me if the item is marked as overrideable ?
If I look at the MSDN documentation for the .NET framework and I see a
property for a class, I see no mention of overrideable in any language
example for get or set functions. Can you point me to a property in the
documentation which shows this ?
As far as events are concerned, I was thinking of the ability to override
the adding, removing, and/or raising of an event. Yet documentation for an
event tells me nothing about these individual event functions for a given
event but just about the event itself. For my own events I make them
virtual
in C++ and, I believe, all functions are virtual in C#. Can I override the
add_XXX, remove_XXX, or raise_XXX for a public event ? What abouyt for a
protected event ?
Forgot:Edward Diener said:I assume when you say Shadows you mean that the derived class creates a
property or event with the same name as the base class and calls down to
the
base class as needed.
What in the documentation tells me if the item is marked as overrideable ?
If I look at the MSDN documentation for the .NET framework and I see a
property for a class, I see no mention of overrideable in any language
example for get or set functions. Can you point me to a property in the
documentation which shows this ?
http://msdn.microsoft.com/library/d...rfsystemwindowsformscontrolclasstexttopic.aspDaniel said:Forgot:
Daniel said:Yes, Shadows is a VB term. Its called a "new" member in C# and I
dunno about C++, though I'm sure you do. I believe Shadows may
actually remove all overloads with the same name, but I'm not sure.
For C# and C++, the declaration should be marked virtual or abstract,
while the VB version will be marked overridable or MustInherit(I
think). Again, overridable and MustIherit are vb specific terms.
You should be able to override them for *virtual* events. Well, only
add_XXX and remove_XXX directly in C#, just as you would a property.
I believe C# requires that you override both add and remove if you
override either, but it does not support raise operators per se,
instead you will simply see a raise_XXX method. So the runtime will
support it entirely, its all a matter of what your language allows.
You may wanna post to the MC++ group for specific syntax and
restrictions that C++ places on event overriding(I put example C#
code at the bottom, unfortunatly I'm not familiar enough with C++ to
give you an example).
In practice, virtual events seem pretty rare, made rarer by the lack
of raise support in C# I think. Its a pity its missing, especially
since C++ and apparently VB in the near future will support them.
Edward Diener said:I do see this in the documentation, after you have pointed it out to me
for
Text.Control. What is amusing is that the VB and C# doc syntax example
will
have the appropriate syntax for telling me that the property is
overrideable, while the C++ does not, for many properties. However this
just
tells me that the doc is wrong since if a property is overrideable in the
other languages it has to be virtual in C++ also. After all, .NET
components
are usable from all .NET languages in the same general way.
I agree with you that there should be more virtual events. I would even go
so far as to say that nearly all properties and events should be
overrideable in derived classes. When I develop components, I almost
always
make all properties and events overrideable. I do not see the overhead of
this as being that great anymore on modern OSs and frameworks. Of course
if
I did not want a derived class to override a property or event, because
its
operation is too specific to my class itself, I would not make it
overrideable. But that is a very rare case.