Brittleness Example:

I agree with Jeff M. This is not the brittleness of classes, it’s a fundamental issue with how to handle polymorphism. You can’t actually implement your `RobotDog` with class inheritance or prototypical inheritance. You are also able to reproduce your example using prototypes and still be in the same pickle (the problem is that you want a RobotDog to be, somehow, associated with a Robot and a Dog, but you haven’t actually implemented that connection).

Interfaces (using TypeScript) can partially come to the rescue, for example:

class Thing implements Movable, Rechargable, MakesSound {…};

Now, in our constructor we can compose a dog with strategy patterns:

let dog = new Thing(new FourLeggedWalker(), new RechargeByEating(), new Barks);

Similarly a robot would have strategies for perhaps 2-legged walking, rechargeable batteries, and beeps (or maybe it implements the NoSound strategy).

A robot dog could then be:

let robotDog = new Thing(new FourLeggedWalker(), new RechargableBatteries(), new Barks());

If we were designing a game where we had different typing of objects running around (real dogs and robot dogs), that would probably fill the bill.

In prototype land, we’d follow a similar procedure (perhaps using something like StampIt, perhaps using factory functions, whatever).

/me wishes Medium would support code blocks, grr

One clap, two clap, three clap, forty?

By clapping more or less, you can signal to us which stories really stand out.