Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Multiple inheritance

Status
Not open for further replies.

androidc

Programmer
May 27, 2003
13
CA
Alright, i could just be an idiot, cuz i can't seem to find any help on the matter (i'm sure it's gotta be there, i just don't know where!!)

(yo, forgive any syntax errors, i'm writing this fairly quickly..)
The idea i have is this. Let's say i have a class clientbase

DEFINE CLASS clientbase AS CUSTOM
PROCEDURE init
SELECT client
SCATTER MEMVAR ;
FIELDS id, name, age
ENDPROC

PROCEDURE getName
RETURN m.name
ENDPROC
PROCEDURE getID...etc. etc.
..
ENDDEFINE

Let's say i also have another class, which is based on a form. Which can either be vcx or a prg with a DEFINE CLASS.
For argument's sake, we'll set up a DEFINE.

DEFINE CLASS clientinterface AS FORM
** add controls here, set the control sources to m.name, m.id, etc
ENDDEFINE

Now, if i wanted to create an object that has both the interface and the base, how would i combine them?

The solutions i've found was
a) instead of creating clientbase, only create clientinterface and then :
DEFINE CLASS client AS clientinterface
PROCEDURE init
PARAMETERS _number
SELECT client
LOCATE FOR id = _number
SCATTER MEMVAR ;
FIELDS id, name, age
ENDPROC
..the rest follows like clientbase

or b)
DEFINE CLASS clientinterface AS FORM
** add controls here
** set the control sources to m.name, m.id, etc

clientaccess = CREATEOBJECT("clientbase", "123")
ENDDEFINE


Of the two, i like the second better, because then i still have my access to the tables in their own object, seperate from anything else.

My question : is there a way that i can merge two classes into one? ie can i inherit from two parents classes instead of just one?

Thanks..
 
There is no ability in VFP to support multiple inheritance. If I understand your code, either of your solutions should work, but strictly speaking neither is an example of multiple inheritance.

Rick
 
oh yeah, i said those were the solutions that i found that enabled me to solve the current problems. but neither permits me to have the objects that i wanted . your first sentence answered my question...not the answer i wanted, but an answer nonetheless.

Thanks
 
You could look at the problem from a different perspective:
I don't know your situation, but while VFP does not support multiple INHERITANCE, it does support what you might call "Multiple implementation".

That is, you can create a class that implements the methods/properties of other classes, whether or not it inherits from those classes, then use this new class as the new standard interface. This is possible because VFP does not have strict type checking:

Even though a method expects a class of type ClientInterface (which could be based on anything... say, Session, or Custom), if you give it a class (say, MyClientForm) derived instead from MyOtherBaseFormClass, VFP is OK about it, as long as the method names/property names of ClientInterface are present in MyClientForm.

This can also be called Polymorphism, though VFP doesn't enforce the strict OOP principles for Polymorphism, it is actually much more flexible.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top