3 ms·
In more traditional OO languages, inheritance might be more limited... Explain. Class based inheritance, with a good metaprogramming model, is strictly more f
by btilly 16y ago
In more traditional OO languages, inheritance might be more limited...
Explain.
Class based inheritance, with a good metaprogramming model, is strictly more flexible than prototype based inheritance because you can easily implement the latter. The shortest implementation that I know of is the following Ruby one:
Proto = Class.new(Class) # Beware: magic.
def Proto.clone
Class.new(self)
end
You can find out more about how to use that at http://snippets.dzone.com/posts/show/3378 http://snippets.dzone.com/posts/show/3378.
- troels 16y agoWell, Ruby's classes are open. So while they are called classes, they are much more similar to prototypes than, say, Java's classes are.
- btilly 16y agoFYI, Ruby's class model is almost directly copied from Smalltalk, which is the classic object oriented language, and is where the phrase "object oriented" was invented. Therefore there are no grounds to suggest that Ruby somehow does not have "real" classes because they don't look like Java's.
- troels 16y agoI weren't proposing any form of value with my statement. Just pointing out that on the scale of {run-time..compile-time} object model, Ruby is closer to the run time end.