Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Class inheritance versus Object (run-time) inheritance
Message
 
To
09/07/1999 20:01:38
General information
Forum:
Visual FoxPro
Category:
Object Oriented Programming
Miscellaneous
Thread ID:
00238626
Message ID:
00239776
Views:
7
David,

>So composition is what happens when I build a Form which contains a typical complement of controls and then I save it as a class ?

Yes, that is composition. It is even composition if you created a form class that contained all your controls.

>The reason this question arose in my mind is because I realized, after creating my first form (which was the one you coached me on, BTW) that I wanted every control in the form to use the same error processing method. My first naive thought was to define a custom error event method for my form and then have it magically become the error event method of its contained controls...but of course, inheritance doesn't work that way so... no free lunch this time. Still, being able to do something like that might be kind of cool.


One reasonable design for this problem is to use delegation. Create every control class so its Error event calls Thisform.error(). The difficulty with inheritance in this scenario is that a subclass is based on the smae base class as its superclass. In your scenario you have, for example, a Textbox that you would like to inherit from a Form. In VFP, inheritance is through exception. That means the subclass inherits everything from its superclass, including its base class, and you override things by implementing them directly in the subclass. That would cause your Texbox to be a Form if you inherited from a Form.

In these situations it is best to use either Delegation or Mediators to handle the requirements.
Previous
Reply
Map
View

Click here to load this message in the networking platform