Abstraction

This is a discussion on Abstraction within the C++ Programming forums, part of the General Programming Boards category; If I have an array of pointers to objects of different classes that are derived from the same base class, ...

  1. #1
    Registered User
    Join Date
    Feb 2004
    Posts
    15

    Abstraction

    If I have an array of pointers to objects of different classes that are derived from the same base class, is this an example of abstraction?

  2. #2
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    22,118
    Sounds more like an example of polymorphism.
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  3. #3
    Registered User
    Join Date
    Feb 2004
    Posts
    15
    Thanks for the reply laserlight! But doesn't polymorphism mean that the members of a derived class are treated like those of its parent (or so Wikipedia says), whereas in my case it's the actually object that's treated like its parent, not its members?

    The whole thing confuses me somewhat...
    Last edited by Nereus; 09-17-2007 at 02:34 PM.

  4. #4
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    22,118
    But does polymorphism mean that the members of a derived class are treated like those of its parent (or so Wikipedia says), whereas in my case it's the actually object that's treated like its parent, not its members?
    Stroustrup defines polymorphism as "providing a single interface to entities of different types". In your example, suppose that you have a virtual function overriden by the derived classes. Then, by looping over the array, you can call this virtual function, and the overriden versions for each object of a given derived class would be called, even though you appeared to call the base class member function. This is polymorphic behaviour since you accessed different member functions (of the derived classes) from a single interface (the base class virtual member function).
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  5. #5
    Registered User
    Join Date
    Feb 2004
    Posts
    15
    Sure, I agree about the use of overridden functions is polymorphism in the way you describe, but isn't the ability to treat the different objects (not their methods) as the same an example abstraction? If not, could you give me an example, as Stroustrup's definition of abstraction has left me non the wiser!

  6. #6
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    22,118
    isn't the ability to treat the different objects (not their methods) as the same an example abstraction
    No. The fact that you have user defined objects implies that abstraction. Think of abstraction as in saying "swap a and b" as opposed to "create a temporary t, assign a to t, assign b to a, assign t to b". Here, the implementation of a swap is hidden by the interface of a swap function. In the case of objects, the implementation of the objects is hidden by its interface, so we can talk in terms of a car rather than a specific collection of doors, windows, wheels etc (which themselves may be an example of abstraction, heh).
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    Look up a C++ Reference and learn How To Ask Questions The Smart Way

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Is there Data Abstraction in C Language?
    By aloysiustany in forum C Programming
    Replies: 16
    Last Post: 12-16-2009, 09:11 AM
  2. Data Abstraction?
    By Matus in forum C Programming
    Replies: 9
    Last Post: 12-11-2008, 09:56 AM
  3. Binary Search Trees Part III
    By Prelude in forum A Brief History of Cprogramming.com
    Replies: 16
    Last Post: 10-02-2004, 04:00 PM
  4. Replies: 11
    Last Post: 03-11-2004, 04:17 PM
  5. data classes and abstraction
    By neo001 in forum C++ Programming
    Replies: 1
    Last Post: 10-15-2002, 09:00 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21