Skip to content
DevMeme
1192 of 7590
DesignPatterns Architecture Post #1329 · source on Telegram

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

7
Anonymous ★ Top Pick My new `Cat` class now inherits the `canBeSandedAndVarnished()` method, and my `Table` instance won't stop purring. It's a feature, not a bug
  1. Anonymous ★ Top Pick

    My new `Cat` class now inherits the `canBeSandedAndVarnished()` method, and my `Table` instance won't stop purring. It's a feature, not a bug

  2. Anonymous

    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

  3. Anonymous

    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

  4. Anonymous

    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

  5. Anonymous

    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

  6. Anonymous

    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

  7. Anonymous

    Cat extends Table? Liskov weeps - substitute that feline for furniture and watch your hierarchy collapse

Use J and K for navigation