Hacker News new | past | comments | ask | show | jobs | submit login

Your code is object-based not object-oriented because of the lack of inheritance.



His example is a little small to see how he would implement inheritance.

Also, inheritance is not a core requirement of OOP. Before you hit that downvote button, consider this: Inheritance allows your class to share attributes and behaviors with another class, and it allows code to recognize that instances of your class have those attributes and behaviors. In other words, when we say "is a", we really mean "does things that match the interface and meaning of". You can accomplish the same thing with "aspects" instead of "inheritance". Following that idea, it is simply a matter of introducing this simple API to add your behavior to an instance:

    add_aspect(&foo, 'Some Aspect Identifier');

And that's just the tip of the iceberg. Check out Art of the Metaobject Protocol (http://www.amazon.com/Art-Metaobject-Protocol-Gregor-Kiczale...) for some huge eye-openers.


>Also, inheritance is not a core requirement of OOP.

The definition I learned was that, if you don't have inheritance, it's object-based. Of course, that was almost 20 years ago; usage might have shifted. I think the example I was given of an object-based language was Ada.




Consider applying for YC's Spring batch! Applications are open till Feb 11.

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: