Find the answer to your Linux question:
Results 1 to 3 of 3
I know the basic answer about how to create a class as ABC. But I don;'t know- - why I have to create a AbstractBaseClass. - In what situations it ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1
    Just Joined!
    Join Date
    May 2009
    Posts
    21

    Reg: C++ abstract classes


    I know the basic answer about how to create a class as ABC.
    But I don;'t know-
    - why I have to create a AbstractBaseClass.
    - In what situations it can be used.
    Can you please anyone help me with an example code base and not like a animal(base) and tiger(derived) relationship example.

    Thanks in advance,
    Madhu

  2. #2
    Super Moderator Roxoff's Avatar
    Join Date
    Aug 2005
    Location
    Nottingham, England
    Posts
    3,892
    We don't normally allow homework questions here, but there may be more to what you're asking than just getting your homework done, so here's some information that might help you.

    Abstract base classes are useful mostly to define an interface or to define the way you want the concrete instances of different classes to communicate with other entities within your code model.

    You don't have to use abstract classes at all, but it can help you keep interfaces separate to your normal code. Normally multiple inheritance in C++ is a Very Bad Thing, but it's not uncommon for a class to inherit from another class and one or more abstract classes that represent interfaces that the class will present.

    I don't think it's appropriate to provide code examples - I think if you create this yourself, you'll understand better what you're doing. If you want to post it here for comment, of course, there may be some that would help.
    Linux user #126863 - see http://linuxcounter.net/

  3. #3
    Linux Guru Cabhan's Avatar
    Join Date
    Jan 2005
    Location
    Seattle, WA, USA
    Posts
    3,252
    As Roxoff said, we don't allow homework questions. I am closing this thread.

    I will give you a bit of information, though. An abstract class allows you to declare that a set of things has a similar behavior, but the details are unknown. To take your example, you have an Animal abstract class that may have an abstract method called "makeNoise". Each Animal now must provide its own implementation: Tiger might return the string "roar", Dog might return "Woof", and Cat would return "Meow". When you have an Animal object, you don't know what type of Animal it is, but you know that it can make a noise.

    If you have a more conceptual question that we can help with, please feel free to start a new thread and ask.

Posting Permissions

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