3 ms·
This raises an interesting question, what added value do "classes" provide over prototypes? The way I see it is if every object (-instance) can be derived from
by galaxyLogic 7y ago
This raises an interesting question, what added value do "classes" provide over prototypes?
The way I see it is if every object (-instance) can be derived from another instance that makes programs harder to understand. Classes are invariants of behavior which all their instances obey, which makes it possible to reuse your understanding of a class to understand all its instances.
It's a bit like the certificate systems we have in the human society. When someone is a certified medical doctor we know more or less what they can do, we don't have to investigate in detail do they have the skill to be a physician.
But I'm not sure this is all there is to the benefit of classes. Is it?
- jecel 7y agoClasses have several roles. They can indicate type. They allow meta programming (where a car is seen not as a car but as a bunch of stuff in the computer's memory). They allow shared state for their instances. With objects that can directly inherit or delegate from each other you can put shared state in a parent object. For the role of type the Self VM used things called "maps" that were not visible at the language level. For meta programming Self introduced "mirror" objects.