Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Visual Inheritance
Message
From
09/11/2006 10:41:22
Keith Payne
Technical Marketing Solutions
Florida, United States
 
 
To
09/11/2006 06:57:25
General information
Forum:
ASP.NET
Category:
Object Oriented Programming
Miscellaneous
Thread ID:
01168385
Message ID:
01168451
Views:
13
>I ve finally worked out how to inherit a form in visual studio C#
>
>Got a few problems
>ONE
>If i have a button in my base class How do I stop that button from working in the base class. I may need its inheritance in some of its inherited forms but not others so I neeed to disable it in the child form
>
>Example
>
>MY BASE FORM
>btnMessage_Click
> messagebox_Show("Base Class");
>(I sometimes want this message to appear)
>
>INHERITED FORM
>btnMessage_click
> messagebox_Show("Child Class");
>I sometimes want this message (or Event) to fire as well as the BaseClass Event OR (and this is what I dont know) NOT FIRE THE BASE CLASS EVENT
>It defaults to running both
>
>TWO
>I have a lot of events in my BASE FORM
>I subclass the form and want to add EVENTS to the new class that either use the BASECLASS events, or rely on results from that BaseClass
>
>
>THREE
>I have an event in my BASECLASS that i want to overide in my ChildForm
>
>There are a number of other questions but I may be able to work it out from the above answers
>
>Thanks in advance
>
>Richard

Richard,

There's a little confusion on terminology in your post. I think that you are saying 'Event' when you mean 'Event Handler'. It sounds like nitpicking, but it is important in OOP because the two are very different animals.

In strict OO terms, event handlers are specific to the class that they are defined in and cannot be directly overridden or stopped from outside the class. You can override methods and properties and you can add more event handlers to the chain, but you cannot remove a class' event handler from outside of the class that defines it. The proper way to handle this situation is to create a property in the base class that will determine whether to perform specific actions within the event handler. Set the property in the derived class' constructor and check it within the event handler.

Also, you cannot fire events in other classes directly. The code contained within the event handler that you want to call from other objects should be moved out of the event handler and into a protected or public method that the event handler calls and your derived classes can call.

Try to always think "black box" when designing classes. It will help avoid these problems and also simplify your class design greatly.

Happy OOP-ing!
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform