Search code examples
c++c++11prototypeparadigms

Can Prototypical OOP Be Considered a Paradigm In C++?


Good day,

considering the following code, could one classify prototypical OOP to be a paradigm in

C++?

#include <iostream>

template< class... Bases >
struct TestClass : public Bases...
{
    int a;
    template< class... Parents >
    TestClass< Parents... >* Create() {
        return new TestClass< Parents... >();
    }
    TestClass< Bases... >* Create() {
        return new TestClass< Bases... >();
    }
};
struct Foo {
    int fizz;
};
struct Bar {
    int buzz;
};
int main()
{
    TestClass< Foo > a;
    a.a = 10;
    a.fizz = 20;
    std::cerr << a.fizz << "\n";
    std::cerr << a.a << "\n";
    auto b = a.Create();
    b->fizz = 30;
    std::cerr << b->fizz << "\n";
    auto c = b->Create< Bar >();
    c->buzz = 357;
    std::cerr << c->buzz << "\n";
    auto d = b->Create< Foo, Bar >();
    d->fizz = 0;
    d->buzz = 1;
    std::cerr << d->fizz << "\n";
    std::cerr << d->buzz << "\n";
    return 0;
}

FYI, I forgot to manage my memory, sorry!


Solution

  • No, I don't think so. The key difference between "prototypical" and "classical" OO is that prototypical OO doesn't have classes: the prototype is itself an object. If the prototype is modified, all objects "inheriting" from it follow suit. In this example, that is not the case.