Click to See Complete Forum and Search --> : basic help


potluck
September 11th, 2002, 12:33 PM
i made the initial form class which is the base class.
i made three more class derived from this one and made them virtual.
now the last class i make has to include all information from all the classes. do i have to use virtual for this??
eg
class form{}
class osap : virtual public form{}
class school : virtual public form{}
class bank : virtual public form{}

>>class apply : virtual public school, virtual public bank, virtual public osap{}
or
>>class apply : public school, public bank, public osap{}

which one would i use to have information from all classes in apply form??

potluck
September 11th, 2002, 12:46 PM
what exactly does this mean??

No static arrays, which means that all the arrays are created dynamically.

jfaust
September 11th, 2002, 12:46 PM
This is a bad hierarchy, and even if you get it working, you will always have trouble with it. The trouble is that this inheritance does not follow the IS-A principle.

Namely, a school is not a form. etc.

This is a dangerous, confusing, costly, un-wise thing to do. This is using OOP in a very non-OOP manner--using the mechanisms to get the result you desire.

There are better ways. I suggest redesign.

Jeff

jfaust
September 11th, 2002, 12:48 PM
One more thing: use a more descriptive subject for your messages. "basic" doesn't help.

Jeff

potluck
September 11th, 2002, 12:50 PM
im not quite sure what you mean by is-a principle.
r u just talking about the naming conventions??

oh and sorry ill name my threads better.

potluck
September 11th, 2002, 01:02 PM
should i create the forms using the new operator. For example,


int main()
{
form *[5];
return 0;
}


how do i Make the form class abstract, this is supposed to mean the class is not supposed to be instantiated but im confused on how this works.

jfaust
September 11th, 2002, 01:05 PM
No, not naming convention, but an OOP concept. You should only use inheritance when it makes sense, not to solve a problem.

class A {};
class B : public A {};

You should be able to say "B is a A". In your example, it does not make sense to say "school is a form"

These types of hierarchies are very troublesome. You should not have a common base class for all object. It's a "bad thing". It's the diamond pattern. It's not someplace you want to go.

This IS-A principle is discussed in Herb Sutter's Exceptional C++, and is known as the "The Liskov Substitution Principle". Here's a link:

http://www.brent.worden.org/tips/2000/liskovSubstitutionPrinciple.html

Jeff

jfaust
September 11th, 2002, 01:06 PM
You need to buy a book and read.

Jeff