Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Constructor firing Inheritance in C#
Message
De
24/01/2006 14:15:20
 
Information générale
Forum:
ASP.NET
Catégorie:
Autre
Divers
Thread ID:
01088705
Message ID:
01089857
Vues:
13
Hi Hugo,

Using virtual methods and eventhandlers in parent classes is good practice to begin with.

As far as modifying existing parent classes to make some method virtual, it shouldn't negatively impact sub-classes that inherit from it (at least, I'm not thinking of anything right off the top of my head, although it might generate some compiler warnings, but warnings are no big deal).

The thing in John's case is that we're talking about eventhandlers, which behave slightly different (need a delegate and all that). And, he wasn't using an overridden eventhandler.

Now, am *I* making sense? <g>

~~Bonnie




>Hi Bonnie,
>
>I have a question about this.
>
>Let me see if I can explain what I am thinking (it is not easy because I usually don't understand this things <g>) but if you need to change your parent class to make some method virtual, then you need access to that parent class source code and furthermore you are messing with all other classes that inherit this base one, shouldn't it be better if, as John expected, the overrided methods of a class were always the ones used, and only if desired you can call the base code from it? Or, on the other hand, shouldn't you always use virtual methods? (Like in Java were all methods are virtual by default)
>
>I am not sure if I am making sense.
>
>>Oh, that's easy John. Declare the Load eventhandler of the base form to be virtual, and then simply override it in the sub-class (you won't even need to put a delegate in the sub-class).
>>
>>~~Bonnie
>>
Bonnie Berent DeWitt
NET/C# MVP since 2003

http://geek-goddess-bonnie.blogspot.com
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform