w3ctag / subclassable-apis-guide

How and why to design APIs that allow subclassing
3 stars 8 forks source link

Why allow subclassing? #5

Open domenic opened 10 years ago

domenic commented 10 years ago

User extensibility, forces good design, etc. Lots of examples for this section would be good.

aredridel commented 10 years ago

My first thought was "Please no!"

Aggregation and delegation tend to make much more useful pieces. I think subclassing forces bad design more often than good.

domenic commented 10 years ago

What I mean by that is it forces you to do things like define Promise.prototype.catch to call this.then, instead of defining it to use a magic algorithmic series of steps. In the former case, people not only get the desired subclassing behavior of only having to override then on their subclass, but they also get a consistent mental model of what catch does, besides "something in C++." That's why subclassing-friendly design is often good design.

aredridel commented 10 years ago

Now that's a good thing. (though subclassing a promise?! That doesn't sound smart at all)