Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

OOP in VFP

17 views
Skip to first unread message

arun...@factsoftware.com

unread,
Jan 8, 2009, 8:16:14 AM1/8/09
to
How to declare Abstruct Class in VFP?

Bernhard Sander

unread,
Jan 8, 2009, 9:43:14 AM1/8/09
to
Hi arundhati,

> How to declare Abstruct Class in VFP?

There is no abstract class definition in VFP.

You could fake it by defining a class with this code in every method:
WAIT WINDOW prog() + ": code not yet defined"


Regards
Bernhard Sander

Olaf Doschke

unread,
Jan 10, 2009, 6:12:41 AM1/10/09
to
VFP does not know the concept of
abstract classes, but you can prevent
a class from being instanciable by
Return .F. in it's init.

You can still put some code in the
abstract's init and dodefault(),
but in subclasses override the
return value to be .T.

That will solve the aspect, that abstract
classes should not be instanciable.

You can still drag&drop such a class
on a form or some other container class
visually, still if you don't override
it's init it will vanish at runtime.

o = CreateObject("abstract")
? VarType(o) && L = Logical, no object
o = CreateObject("concrete")
? Vartype(o) && Object = Instance of concrete class

Define Class Concrete as Abstract
Procedure Init()
DoDefault()
Return .T.
Endproc
EndDefine

Define Class Abstract as custom
Procedure Init()
Return .F.
EndProc
EndDefine

It's the easiest solution to not forget
to subclass such abstract classes, otherwise
you can easily have an abstract class
wrking concrete just by setting some
of it's properties or using the dynamics
of the VFP language like Macrosubstitution:

Define Class abstractButton As Commandbutton
procedure Click()
Eval(This.cClickcode)

Olaf Doschke

unread,
Jan 10, 2009, 6:23:51 AM1/10/09
to
> Define Class abstractButton As Commandbutton
> procedure Click()
> Eval(This.cClickcode)

Sorry, I hit submit too early:

Define Class abstractButton As Commandbutton

This.cClickCode = "ThisForm.SomeMethod()"

Procedure Click()
Eval(This.cClickCode)
Endproc
Enddefine

Now you could add this abstract button to
forms and then make it concrete by setting
the cClickCode appropriately.

This is not even using macro substitution,
eval is sufficient here (and faster).

Bye, Olaf.

0 new messages