5 |
The LA Fox Developer
Newsletter
|
February 1996
|
Polymorphism
(Con’t from page 4)
event even though other classes in the hierarchy also have double click code.
Let’s look at this concept another way. You are your parents’ child. However, both you and your parents share common “reactions” to events. For example, if you got hit on the head with a stick-the event-you would have a reaction. If one of your parents got hit on the head with a stick, they would also have a reaction (though they wouldn’t like it either).
Note that this example breaks down a little, since VFP doesn’t support multiple inheritance. That is, you are the descendent of both your parents-you inherit from both of them. Other languages, notably C++, do support multiple inheritance. However, there is some debate about how much multiple inheritance adds to most applications (other than much complexity, that is).
What you might be wondering is, why would polymorphism work any differently than this article is describing? Well, what could happen (and does sometimes in other languages) is that without polymorphism, if you sent a double click message to the child’s form, the base class code would fire (not the child’s). which is not what you want. The fact that polymorphic behavior is automatic(that is, you don’t have to create any special functions for polymorphism
to work correctly as you do in other languages like C++) is a nice benefit of using VFP.
Okay, back to the code above, If you change the CREATEOBJECT to:
oEXAMPLE=CREATEOBJECT("PARENT")
oExample.Show()
READ EVENTS
and then double click the form, you’ll see the WAIT WINDOW for the parent. Sounds good, right? Pretty easy, right? That’s all there is to it!!!
Omitting code in a class
What would happen if we used:
oExample=CREATEOBJECT("CHILD")
/oExample.Show()
READ EVENTS
and we left out the procedure for the DBLCLICKO procedure? Simple. The code for the next member up the
|
class hierarchy is called. Thus, you’d see the WAIT WINDOW for parent again. If there is no code in the method code for the object you’re double clicking VFP looks up the class hierarchy for method code it can execute. When VFP finds method code for double
click
up the hierarchy it executes it!
As I hope you see, polymorphism is easy to understand, but hard to spell’
(About the Author: Jim Haentzschel is President of
Hurricane Technology in Alexandria, VA specializing in
FoxPro applications development and in user training.
Jim can be reached at CompuServe 75166,236 and at
(703) 684-1393.)
Out and About
(Con't, from page
2)
didn’t receive a newsletter last month. If your dues expired in ‘94, you probably didn’t receive one this month. So everyone make sure you look at your mailing label for membership/expiration status and please respond accordingly. Membership dues are $45, payable to LA Fox, and can be mailed to Allen Garfein,
3449
Beethoven, Los Angeles, CA 90066, or Barry R. Lee, P.O. Box 6624, Huntington Beach, CA 92615-6624, or brought to the next meeting. Dues help defray the cost of the meeting rooms, newsletters, speaker expenses, etc.
Catching Up With Les Les Pinter’s VFP book,
The
Pinter Visual FoxPro Programming Handbook
,
has finally hit the shelves of the better bookstores in the area. Expect a review in the next couple of months. And he
finally
has his forum up on CompuServe. Just key in “GO PINTER”. If you purchase the VFP book, you’ll be able to download all the source code to the new book, as well as past issues of the
Pinter FoxPro Letter,
from the Pinter Forum.
Elsewhere
For at least the next couple of months, the Orange
County
FoxPro
Developers
Group
will have a new
meeting location at AST Research.
Orange County FoxPro Developers Group
AST Research, Inc.
16215 Afton Parkway
Irvine, CA 92713
From the 405, exit at Sand Canyon and go north to Afton Parkway. Proceed east on Alton Parkway to AST Re
(Con't, page 8)
|
Page 5
|
5 |