Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Does vfp support polymorphism?
Message
 
À
20/06/2003 06:14:28
Metin Emre
Ozcom Bilgisayar Ltd.
Istanbul, Turquie
Information générale
Forum:
Visual FoxPro
Catégorie:
Programmation Orientée Object
Divers
Thread ID:
00802118
Message ID:
00802465
Vues:
23
Here is a very weak example (because Fox is a weakly typed language).
circ = CREATEOBJECT("circle")
drawsomething(circ)

FUNCTION drawsomething (ashape as myshape)
ashape.draw()
endfunc

DEFINE CLASS myshape as Custom
	PROCEDURE draw
		?"draw shape"
	endproc
enddefine

DEFINE CLASS circle as myshape
	PROCEDURE draw
		?"draw circle"
		DODEFAULT()
	endproc
ENDDEFINE
prints
"draw circle"
"draw shape"

The point is that you instantiate an instance of a subclass, pass it to some method that only knows about the parent and when it calls a method of the passed object you get the subclassed behavior, not the parent behavior. We know that we passed it a circle, but the function only had to know about an abstract shape. Next time we pass it a square we dont have to modify the drawsomthing method, polymorphism makes sure we get the correct behavior.

Polymorphism is what gives us frameworks and low coupling.

>i have gone i java course lastdays. i couldn't learned java (it confused me) but i learned polymorphism. does vfp support polymorphism if answer yes how?
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform