Jump to content

  • Log In with Google      Sign In   
  • Create Account


taby

Member Since 10 Feb 2005
Offline Last Active Sep 06 2014 01:16 PM

Posts I've Made

In Topic: Four pillars of object oriented programming

10 May 2014 - 01:07 PM

Thanks to everyone for putting in their two cents. Learned a lot.


In Topic: Four pillars of object oriented programming

10 May 2014 - 09:38 AM

Whoa, whoa whoa, OP.

Inheritance, abstract classes and polymorphism are not the core or most important parts of OO. They're rarely used compared to the rest of OO!!

As mentioned earlier, composition is the killer feature, and SOLID is the 5 pillars.
http://en.m.wikipedia.org/wiki/SOLID_(object-oriented_design)

 

To me it seems like the four pillars are about language features, where the SOLID 5 pillars are more like design choices.


In Topic: Four pillars of object oriented programming

09 May 2014 - 02:36 PM

I reimplemented the polymorphism example to take into account multiple types, like Glass_Knife suggested (I think):

 

#include <iostream>
using std::cout;
using std::endl;


// Base class with virtual member function
class A
{
public:
    virtual void talk(void)
    {
        cout << "Class A" << endl;
    }
};
 
class B: public A
{
public:
    void talk(void)
    {
        cout << "Class B" << endl;
    }
};

int main(void)
{
    A a;
    B b;

    A *a_ptr = &a;
    a_ptr->talk();

    a_ptr = &b;
    a_ptr->talk();

    // Also see function overloading as an example of polymorphism
    // ie:
    // int add(int a, int b) { return a + b }
    // float add(float a, float b) { return a + b }
    //
    // Also see templates
    // ie:
    // STL containers

    return 0;
}

In Topic: Four pillars of object oriented programming

09 May 2014 - 02:23 PM

If it seems that no one can agree what the "four pillars of OOP" are, perhaps you should take that as a sign that the idea of "four pillars" is bullshit.

 

LOL, perhaps that's true. :)


In Topic: Four pillars of object oriented programming

09 May 2014 - 02:22 PM

 

I think you've got it for the first three.  The polymorphisim, however, is missing something.  This means that objects can change (morph) into different types (poly) at runtime:

int main(void)
{
    A a = B;
    a.talk(); // calls B.talk()

    a = C;
    a.talk(); // calls C.talk()

 
    return 0;
}

That sounds reasonable. I'll look into it. Thank you.


PARTNERS