Skip to main content

Code Smell 323 - Harness-Driven Superclass

You didn't split the class. You hid half of it upstairs

Updated 7 min readMarkdown
Part of seriesCode Smells
Code Smell 323 - Harness-Driven Superclass

TL;DR: Don't create a superclass just to pass a size limit. Move behavior into collaborators with delegation.

Problems πŸ˜”

Solutions πŸ˜ƒ

  1. Extract cohesive collaborators
  2. Delegate, don't inherit
  3. Split by responsibility
  4. Name by domain concept
  5. Measure cohesion, not size

Refactorings βš™οΈ

https://maximilianocontieri.com/refactoring-023-replace-inheritance-with-delegation

https://maximilianocontieri.com/refactoring-007-extract-class

Context πŸ’¬

A harness caps class length, property count, and method count, and it rejects code that goes over.

Some limits work as good alarms for growing responsibilities (long functions, too many attributes, too many methods).

You ask an AI assistant to make the failing class pass.

The shortest path is moving half of its members into a new parent class.

The count per class drops, the check turns green, and nothing else changes.

The behavior stays in the same object, because the child inherits everything the parent holds.

Developers did this for years to dodge size rules in code reviews.

Now the assistant does it in seconds, and it stacks as many layers as the harness needs.

The parent has no meaning of its own, so it gets names like Base, Part, or Abstract.

You use inheritance to share code, not to model a specialization.

Johnson and Foote suggested factoring shared behavior into abstract superclasses back in 1988, and that advice fits frameworks that share real protocols, not size quotas.

The metric improves and the design gets worse.

That's Goodhart's law at work.

Sample Code πŸ’»

Wrong 🚫

// The harness rejects over 300 lines, 10 attributes or 20 methods.
//
// The agent that tries to prove the Riemann Hypothesis kept
// growing: every new theory and sublemma added methods and
// state to it.
//
// To pass the harness, the assistant moved the overflow
// into superclasses that exist only to hold members.

abstract class ProofBase {
  protected lemmas = new Set<string>();
  protected log: string[] = [];
  // 300 attributes more

  protected record(step: string): void {
    this.log.push(step);
  }

  protected assume(claim: string): void {
    this.lemmas.add(claim);
  }
}

abstract class EulerProductPart extends ProofBase {
  protected eulerProduct(s: number): number {
    this.record(`euler product at ${s}`);
    return 0; // ...
  }

  protected primeCounting(n: number): number {
    return 0; // ...
  }
}

abstract class FunctionalEquationPart extends EulerProductPart {
  protected reflect(s: number): number {
    return 1 - s;
  }

  protected xiSymmetry(s: number): boolean {
    return true; // ...
  }
}

abstract class ZeroSearchPart extends FunctionalEquationPart {
  protected knownZeros: number[] = [];

  protected verifyZerosUpTo(height: number): boolean {
    return true; // ...
  }
}

class RiemannProofAgent extends ZeroSearchPart {
  prove(): boolean {
    this.assume("zeros lie in 0 < Re(s) < 1");
    this.eulerProduct(2.0);
    this.xiSymmetry(0.5);
    return this.verifyZerosUpTo(1e12);
  }

  // 300 methods more
}
class LemmaLedger {
  private lemmas = new Set<string>();
  private log: string[] = [];

  record(step: string): void {
    this.log.push(step);
  }

  assume(claim: string): void {
    this.lemmas.add(claim);
  }
}

class EulerProduct {
  constructor(private readonly ledger: LemmaLedger) {}

  evaluateAt(s: number): number {
    this.ledger.record(`euler product at ${s}`);
    return 0; // ...
  }

  primeCounting(n: number): number {
    return 0; // ...
  }
}

class FunctionalEquation {
  reflect(s: number): number {
    return 1 - s;
  }

  checkSymmetryAt(s: number): boolean {
    return true; // ...
  }
}

class ZeroVerification {
  private knownZeros: number[] = [];

  verifyUpTo(height: number): boolean {
    return true; // ...
  }
}

class RiemannProofAgent {
  constructor(
    private readonly ledger: LemmaLedger,
    private readonly eulerProduct: EulerProduct,
    private readonly functionalEquation: FunctionalEquation,
    private readonly zeroVerification: ZeroVerification
  ) {}

  prove(): boolean {
    this.ledger.assume("zeros lie in 0 < Re(s) < 1");
    this.eulerProduct.evaluateAt(2.0);
    this.functionalEquation.checkSymmetryAt(0.5);
    return this.zeroVerification.verifyUpTo(1e12);
  }
}

Detection πŸ”

[X] Semi-Automatic

Search for abstract classes with a single subclass that no code uses as a type.

If nobody type-hints the parent, it exists only to hold members.

Look for parent names like Base, Part, Helper, or Abstract, and for hierarchies that got deeper right after you introduced a size limit.

Check the history: a failed size check followed by a commit that adds a parent and moves members up is the signature.

Exceptions πŸ›‘

A parent class is fine when several subclasses share a real protocol and callers depend on the parent type.

In that case, the parent models a concept, and you can explain it without mentioning the size limit.

Tags 🏷️

  • Hierarchies

Level πŸ”‹

[x] Intermediate

Why the Bijection Is Important πŸ—ΊοΈ

Every class in your model should match a concept in the MAPPER.

A parent class created to hold overflow members matches nothing.

Nobody in the domain would say "this thing is a kind of leftover bucket".

When you delegate to collaborators, each one maps to a concept you can name, and the bijection stays intact.

When you hide members upstairs, the original object keeps every responsibility, and you add coupling between the layers.

AI Generation πŸ€–

AI generators create this smell often when you ask them to respect a size limit.

They optimize for the check you gave them, and moving members into a parent is the smallest diff that turns it green.

They don't stop to ask whether the new parent models anything.

Humans took this shortcut when they felt the pressure of a review rule, but an assistant takes it on every failing class, without hesitation and without feeling any shame.

AI Detection 🧲

AI can detect it if you point it at the pattern.

Try: "Find abstract classes with a single subclass that no code uses as a type, and explain what concept each one models."

Without that prompt, the hierarchy looks tidy, the harness passes, and most assistants won't flag the code they just wrote.

Try Them! πŸ› 

Remember: AI Assistants make lots of mistakes

Suggested Prompt: Replace the intermediate superclasses that only hold overflow members with collaborator objects, and delegate to them from the original class

Without Proper Instructions With Specific Instructions
ChatGPT ChatGPT
Claude Claude
Perplexity Perplexity
Copilot Copilot
You You
Gemini Gemini
DeepSeek DeepSeek
Meta AI Meta AI
Grok Grok
Qwen Qwen

Conclusion 🏁

A size limit is an alarm, not a design.

When the alarm rings, split the responsibilities instead of moving them to a parent.

Delegate to small objects you can name, test, and replace.

Don't let the assistant pass the harness by hiding the mess one floor up.

Relations πŸ‘©β€β€οΈβ€πŸ’‹β€πŸ‘¨

https://maximilianocontieri.com/code-smell-11-subclassification-for-code-reuse

https://maximilianocontieri.com/code-smell-58-yo-yo-problem

https://maximilianocontieri.com/code-smell-136-classes-with-just-one-subclass

https://maximilianocontieri.com/code-smell-14-god-objects

https://maximilianocontieri.com/code-smell-147-too-many-methods

https://maximilianocontieri.com/code-smell-34-too-many-attributes

https://maximilianocontieri.com/code-smell-320-vanity-coverage

https://maximilianocontieri.com/code-smell-313-workslop-code

More Information πŸ“•

Designing Reusable Classes

Composition over inheritance

Fragile base class

Replace Inheritance with Delegation

Large Class

The same trick works against any metric you can game, like coverage or line count.

Quote

When a measure becomes a target, it ceases to be a good measure.

Marilyn Strathern

Disclaimer πŸ“˜

Code Smells are my opinion.

Credits πŸ™

Photo by Hafsa LR on Unsplash


This article is part of the CodeSmell Series.

https://maximilianocontieri.com/how-to-find-the-stinky-parts-of-your-code

About the author

  • I’m a senior software engineer loving clean code, and declarative designs. S.O.L.I.D. and agile methodologies fan.

No comments yet. Be the first to comment.

Code Smells

Part 1 of 50

In this series, we will see several symptoms and situations that make us doubt the quality of our developments. We will present possible solutions. Most are just clues. They are no hard rules.

Up nextCode Smell 322 - Request Data in Long-Lived Variables (PHP Vulnerability)Your request is gone. Your pointer is not.