News for hackers. Stuff that matters.
Re:The Repeated Deaths of OOP (2015) by lolinder on Sunday June 06, 2021 @11:00PM (#27418552)
> The mechanism by which the cells are copied does involve DNA, but it and the proteins involved are an implementation detail.

Well, yes, anything inside the cell is, when modeled as an object, an implementation detail. External behavior is all that matters.

What always strikes me funny about prototypal inheritance is that it seems like a special case of composition, one that just happens to do all the necessary delegation for you.

In the case of the cell, I can model mitosis by having the two cells name their parent as the prototype, or I can define in the code that they're composed of the same stuff and delegate method calls the same way. The end result is the same, but composition is more flexible.

In JavaScript, prototypes have less boilerplate, but it's possible to have a language that eliminates most of the boilerplate for delegation as well (see Kotlin's delegation feature [0])

What do I gain by using a prototype instead of composition with delegation?

[0] https://kotlinlang.org/docs/delegation.html

There are no comments on this comment yet.