CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 8 of 8

Thread: basic help

  1. #1
    Join Date
    Jul 2002
    Posts
    56

    basic help

    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??

  2. #2
    Join Date
    Jul 2002
    Posts
    56

    and

    what exactly does this mean??

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

  3. #3
    Join Date
    Mar 2002
    Location
    California
    Posts
    1,582
    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

  4. #4
    Join Date
    Mar 2002
    Location
    California
    Posts
    1,582
    One more thing: use a more descriptive subject for your messages. "basic" doesn't help.

    Jeff

  5. #5
    Join Date
    Jul 2002
    Posts
    56
    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.

  6. #6
    Join Date
    Jul 2002
    Posts
    56
    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.

  7. #7
    Join Date
    Mar 2002
    Location
    California
    Posts
    1,582
    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/200...Principle.html

    Jeff

  8. #8
    Join Date
    Mar 2002
    Location
    California
    Posts
    1,582
    You need to buy a book and read.

    Jeff

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured