A Purr-fectly Flawed Inheritance Model
Description
The image features the surreal 'Meme Man' character - a smooth, grey, disembodied head - superimposed on the body of a person in a blue shirt and tie, sitting at a desk with a laptop. The character is rubbing the back of their neck in a gesture of awkwardness or mistake. The text at the top reads, 'When class Cat extends Table because it has four legs.' Next to the character's head, the word 'OOPS' is written in a simple, outlined font. The meme humorously illustrates a classic misunderstanding of Object-Oriented Programming (OOP) principles. It satirizes the flawed logic of using inheritance for a 'has-a' relationship (both have four legs) instead of an 'is-a' relationship (a cat is not a type of table). This is a common anti-pattern that experienced developers instantly recognize as a sign of a junior programmer's mistake, leading to a rigid and illogical class structure
Comments
7Comment deleted
My new `Cat` class now inherits the `canBeSandedAndVarnished()` method, and my `Table` instance won't stop purring. It's a feature, not a bug
Latest code review: “class Cat extends Table.” Looks fine until Liskov drops a 20-pound roast on the instance and the subclass jumps off the call stack, hissing about unsupported load
This is the same inheritance hierarchy that led to our authentication system where Admin extends User extends Guest because "they're all people who access the system" - now every guest has dormant sudo privileges waiting to be discovered
This is the architectural equivalent of inheriting from AbstractVehicle because your coffee maker has a power button and so does your car. Sure, they both have four legs - I mean, wheels - but when your Cat class suddenly inherits a setTablecloth() method and your polymorphic dinner party tries to serve food on a feline, you'll realize that shared attributes don't justify inheritance. Composition over inheritance isn't just a principle; it's what prevents your codebase from becoming a taxonomical nightmare where everything is-a something it definitely is-not. The real OOPS here is that this mistake usually survives code review until production, when someone tries to instantiate new Cat() and wonders why it implements the Furniture interface
If “Cat extends Table” made it past code review, your domain model is an IKEA catalog and LSP just knocked your coffee off the interface
Cat extends Table because it has four legs - classic attribute-driven inheritance; Liskov cries, composition says “told you so,” and suddenly the cat implements ILoadBearing
Cat extends Table? Liskov weeps - substitute that feline for furniture and watch your hierarchy collapse