TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

Prototype based vs. class based inheritance

35 pointsby brandonkmover 14 years ago

5 comments

silentbicycleover 14 years ago
See: <a href="http://www.c2.com/cgi/wiki?ClassesPrototypesComparison" rel="nofollow">http://www.c2.com/cgi/wiki?ClassesPrototypesComparison</a><p>In my experience, prototype-based OOP is less prone to the typical OOP over-analysis - if you just need one object that does something, <i>you just assemble it, that's it, problem solved</i>. Since the default stance isn't designing a generic class for all possible subtypes that exhibit related behavior and blah blah blah, there's less push toward overthinking things.<p>Prototype-based OOP is also well-suited to runtime modification, since the underlying implementation is usually simpler, but that's a distant second to the above benefit. And while prototypes are sometimes assumed to be less efficient than classes, look at the research from Self* - While some popular languages have poor implementations, it's not <i>inherently</i> less efficient.<p>Also, I suspect prototypes integrate more smoothly with non-OOP code than classes, based on experience with Lua (which isn't strictly OOP, but typically uses prototypes). To some extent, this blurs with dynamic typing, though - there's only one statically typed + prototype-based OOP language I know of, Günther Blaschek's Omega (described in _Object-Oriented Programming With Prototypes_).<p>* <a href="http://selflanguage.org/documentation/published/index.html" rel="nofollow">http://selflanguage.org/documentation/published/index.html</a> Some of the people involved later worked on the "JVM". Perhaps you've heard of it?
评论 #2000385 未加载
评论 #1999828 未加载
russellallenover 14 years ago
Some thoughts:<p>Given a sufficiently flexible and late-bound class system (like Smalltalk's), the differences between prototypes and classes can blur.<p>But in general I would say that it is easier to build classes on top of prototype systems than vice versa, which is one argument for prototypes.<p>All prototype implementations aren't the same, though, any more than Smalltalk and C++ both have the same class systems! Javascript and Self are quite different in some ways, especially when it comes to delegation (ie inheritance) and iolanguage and research such as Kevo are different again.<p>Despite the first answer to the linked question, I don't think that either class based or prototype based languages are easier to write a VM for.<p>What attracts me most is that prototype systems are conceptually simpler in an Occam's Razor sort of way. Instead of needing two concepts: classes and instances, we only need one: objects.
评论 #1999743 未加载
评论 #2000751 未加载
mlnover 14 years ago
this is what Guy Steele has to say. <a href="http://people.csail.mit.edu/gregs/ll1-discuss-archive-html/msg03277.html" rel="nofollow">http://people.csail.mit.edu/gregs/ll1-discuss-archive-html/m...</a>
评论 #2000171 未加载
评论 #2000771 未加载
评论 #2000117 未加载
bgriggs1over 14 years ago
Here's a useful comparative demo that makes this a little easier to differentiate: <a href="http://alexsexton.com/inheritance/demo/" rel="nofollow">http://alexsexton.com/inheritance/demo/</a>
yycomover 14 years ago
Can someone point to a non-trivial example using prototypal inheritance?