# 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 😔

- Inheritance without a real specialization
- Hidden [coupling](https://maximilianocontieri.com/coupling-the-one-and-only-software-design-problem) to the superclass
- [Yo-yo navigation](https://maximilianocontieri.com/code-smell-58-yo-yo-problem) across files
- Fragile base class
- Vague [parent names](https://maximilianocontieri.com/what-exactly-is-a-name-part-i-the-quest)
- Responsibilities stay in one object
- [Bijection](https://maximilianocontieri.com/the-one-and-only-software-design-principle) violation

# 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](https://maximilianocontieri.com/ai-coding-tip-022-give-ai-a-harness-to-work-with) 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](https://maximilianocontieri.com/code-smell-03-functions-are-too-long), [too many attributes](https://maximilianocontieri.com/code-smell-34-too-many-attributes), [too many methods](https://maximilianocontieri.com/code-smell-147-too-many-methods)).

You [ask an AI assistant](https://maximilianocontieri.com/ai-coding-tip-019-tell-the-ai-why-not-just-what) to make the failing class pass.

The [shortest path](https://maximilianocontieri.com/ai-coding-tip-015-force-the-ai-to-obey-you) 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](https://maximilianocontieri.com/ai-coding-tip-027-force-code-standards) 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](https://maximilianocontieri.com/code-smell-11-subclassification-for-code-reuse), not to model a specialization.

[Johnson and Foote](http://www.laputan.org/drc.html) 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](https://en.wikipedia.org/wiki/Goodhart%27s_law) at work.

# Sample Code 💻

## Wrong 🚫

<!-- [Gist Url](https://gist.github.com/mcsee/b2c43bd35672f7c42d5963b34fa022d4) -->

```typescript
// 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
}
```

## Right 👉

<!-- [Gist Url](https://gist.github.com/mcsee/fa91a71021fee5233b971f27281ec10e) -->

```typescript
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](https://maximilianocontieri.com/code-smell-38-abstract-names), 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](https://maximilianocontieri.com/what-is-wrong-with-software), 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](https://maximilianocontieri.com/what-is-wrong-with-software).

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](https://maximilianocontieri.com/the-one-and-only-software-design-principle) stays intact.

When you hide members upstairs, the original object keeps every responsibility, and you add [coupling](https://maximilianocontieri.com/coupling-the-one-and-only-software-design-problem) 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](https://chat.openai.com/?q=Correct+and+explain+this+code%3A+%60%60%60typescript%0D%0A%2F%2F+The+harness+rejects+over+300+lines%2C+10+attributes+or+20+methods.%0D%0A%2F%2F%0D%0A%2F%2F+The+agent+that+tries+to+prove+the+Riemann+Hypothesis+kept%0D%0A%2F%2F+growing%3A+every+new+theory+and+sublemma+added+methods+and%0D%0A%2F%2F+state+to+it.%0D%0A%2F%2F%0D%0A%2F%2F+To+pass+the+harness%2C+the+assistant+moved+the+overflow%0D%0A%2F%2F+into+superclasses+that+exist+only+to+hold+members.%0D%0A%0D%0Aabstract+class+ProofBase+%7B%0D%0A++protected+lemmas+%3D+new+Set%3Cstring%3E%28%29%3B%0D%0A++protected+log%3A+string%5B%5D+%3D+%5B%5D%3B%0D%0A++%2F%2F+300+attributes+more%0D%0A%0D%0A++protected+record%28step%3A+string%29%3A+void+%7B%0D%0A++++this.log.push%28step%29%3B%0D%0A++%7D%0D%0A%0D%0A++protected+assume%28claim%3A+string%29%3A+void+%7B%0D%0A++++this.lemmas.add%28claim%29%3B%0D%0A++%7D%0D%0A%7D%0D%0A%0D%0Aabstract+class+EulerProductPart+extends+ProofBase+%7B%0D%0A++protected+eulerProduct%28s%3A+number%29%3A+number+%7B%0D%0A++++this.record%28%60euler+product+at+%24%7Bs%7D%60%29%3B%0D%0A++++return+0%3B+%2F%2F+...%0D%0A++%7D%0D%0A%0D%0A++protected+primeCounting%28n%3A+number%29%3A+number+%7B%0D%0A++++return+0%3B+%2F%2F+...%0D%0A++%7D%0D%0A%7D%0D%0A%0D%0Aabstract+class+FunctionalEquationPart+extends+EulerProductPart+%7B%0D%0A++protected+reflect%28s%3A+number%29%3A+number+%7B%0D%0A++++return+1+-+s%3B%0D%0A++%7D%0D%0A%0D%0A++protected+xiSymmetry%28s%3A+number%29%3A+boolean+%7B%0D%0A++++return+true%3B+%2F%2F+...%0D%0A++%7D%0D%0A%7D%0D%0A%0D%0Aabstract+class+ZeroSearchPart+extends+FunctionalEquationPart+%7B%0D%0A++protected+knownZeros%3A+number%5B%5D+%3D+) | [ChatGPT](https://chat.openai.com/?q=Replace+the+intermediate+superclasses+that+only+hold+overflow+members+with+collaborator+objects%2C+and+delegate+to+them+from+the+original+class%3A+%60%60%60typescript%0D%0A%2F%2F+The+harness+rejects+over+300+lines%2C+10+attributes+or+20+methods.%0D%0A%2F%2F%0D%0A%2F%2F+The+agent+that+tries+to+prove+the+Riemann+Hypothesis+kept%0D%0A%2F%2F+growing%3A+every+new+theory+and+sublemma+added+methods+and%0D%0A%2F%2F+state+to+it.%0D%0A%2F%2F%0D%0A%2F%2F+To+pass+the+harness%2C+the+assistant+moved+the+overflow%0D%0A%2F%2F+into+superclasses+that+exist+only+to+hold+members.%0D%0A%0D%0Aabstract+class+ProofBase+%7B%0D%0A++protected+lemmas+%3D+new+Set%3Cstring%3E%28%29%3B%0D%0A++protected+log%3A+string%5B%5D+%3D+%5B%5D%3B%0D%0A++%2F%2F+300+attributes+more%0D%0A%0D%0A++protected+record%28step%3A+string%29%3A+void+%7B%0D%0A++++this.log.push%28step%29%3B%0D%0A++%7D%0D%0A%0D%0A++protected+assume%28claim%3A+string%29%3A+void+%7B%0D%0A++++this.lemmas.add%28claim%29%3B%0D%0A++%7D%0D%0A%7D%0D%0A%0D%0Aabstract+class+EulerProductPart+extends+ProofBase+%7B%0D%0A++protected+eulerProduct%28s%3A+number%29%3A+number+%7B%0D%0A++++this.record%28%60euler+product+at+%24%7Bs%7D%60%29%3B%0D%0A++++return+0%3B+%2F%2F+...%0D%0A++%7D%0D%0A%0D%0A++protected+primeCounting%28n%3A+number%29%3A+number+%7B%0D%0A++++return+0%3B+%2F%2F+...%0D%0A++%7D%0D%0A%7D%0D%0A%0D%0Aabstract+class+FunctionalEquationPart+extends+EulerProductPart+%7B%0D%0A++protected+reflect%28s%3A+number%29%3A+number+%7B%0D%0A++++return+1+-+s%3B%0D%0A++%7D%0D%0A%0D%0A++protected+xiSymmetry%28s%3A+number%29%3A+boolean+%7B%0D%0A++++return+true%3B+%2F%2F+...%0D%0A++%7D%0D%0A%7D%0D%0A%0D%0Aabstract+class+ZeroSearchPart+extends+FunctionalEquationPart+%7B%0D%0A++protected+knownZeros%3A+number%5B%5D+%3D+) |
| [Claude](https://claude.ai/new?q=Correct+and+explain+this+code%3A+%60%60%60typescript%0D%0A%2F%2F+The+harness+rejects+over+300+lines%2C+10+attributes+or+20+methods.%0D%0A%2F%2F%0D%0A%2F%2F+The+agent+that+tries+to+prove+the+Riemann+Hypothesis+kept%0D%0A%2F%2F+growing%3A+every+new+theory+and+sublemma+added+methods+and%0D%0A%2F%2F+state+to+it.%0D%0A%2F%2F%0D%0A%2F%2F+To+pass+the+harness%2C+the+assistant+moved+the+overflow%0D%0A%2F%2F+into+superclasses+that+exist+only+to+hold+members.%0D%0A%0D%0Aabstract+class+ProofBase+%7B%0D%0A++protected+lemmas+%3D+new+Set%3Cstring%3E%28%29%3B%0D%0A++protected+log%3A+string%5B%5D+%3D+%5B%5D%3B%0D%0A++%2F%2F+300+attributes+more%0D%0A%0D%0A++protected+record%28step%3A+string%29%3A+void+%7B%0D%0A++++this.log.push%28step%29%3B%0D%0A++%7D%0D%0A%0D%0A++protected+assume%28claim%3A+string%29%3A+void+%7B%0D%0A++++this.lemmas.add%28claim%29%3B%0D%0A++%7D%0D%0A%7D%0D%0A%0D%0Aabstract+class+EulerProductPart+extends+ProofBase+%7B%0D%0A++protected+eulerProduct%28s%3A+number%29%3A+number+%7B%0D%0A++++this.record%28%60euler+product+at+%24%7Bs%7D%60%29%3B%0D%0A++++return+0%3B+%2F%2F+...%0D%0A++%7D%0D%0A%0D%0A++protected+primeCounting%28n%3A+number%29%3A+number+%7B%0D%0A++++return+0%3B+%2F%2F+...%0D%0A++%7D%0D%0A%7D%0D%0A%0D%0Aabstract+class+FunctionalEquationPart+extends+EulerProductPart+%7B%0D%0A++protected+reflect%28s%3A+number%29%3A+number+%7B%0D%0A++++return+1+-+s%3B%0D%0A++%7D%0D%0A%0D%0A++protected+xiSymmetry%28s%3A+number%29%3A+boolean+%7B%0D%0A++++return+true%3B+%2F%2F+...%0D%0A++%7D%0D%0A%7D%0D%0A%0D%0Aabstract+class+ZeroSearchPart+extends+FunctionalEquationPart+%7B%0D%0A++protected+knownZeros%3A+number%5B%5D+%3D+) | [Claude](https://claude.ai/new?q=Replace+the+intermediate+superclasses+that+only+hold+overflow+members+with+collaborator+objects%2C+and+delegate+to+them+from+the+original+class%3A+%60%60%60typescript%0D%0A%2F%2F+The+harness+rejects+over+300+lines%2C+10+attributes+or+20+methods.%0D%0A%2F%2F%0D%0A%2F%2F+The+agent+that+tries+to+prove+the+Riemann+Hypothesis+kept%0D%0A%2F%2F+growing%3A+every+new+theory+and+sublemma+added+methods+and%0D%0A%2F%2F+state+to+it.%0D%0A%2F%2F%0D%0A%2F%2F+To+pass+the+harness%2C+the+assistant+moved+the+overflow%0D%0A%2F%2F+into+superclasses+that+exist+only+to+hold+members.%0D%0A%0D%0Aabstract+class+ProofBase+%7B%0D%0A++protected+lemmas+%3D+new+Set%3Cstring%3E%28%29%3B%0D%0A++protected+log%3A+string%5B%5D+%3D+%5B%5D%3B%0D%0A++%2F%2F+300+attributes+more%0D%0A%0D%0A++protected+record%28step%3A+string%29%3A+void+%7B%0D%0A++++this.log.push%28step%29%3B%0D%0A++%7D%0D%0A%0D%0A++protected+assume%28claim%3A+string%29%3A+void+%7B%0D%0A++++this.lemmas.add%28claim%29%3B%0D%0A++%7D%0D%0A%7D%0D%0A%0D%0Aabstract+class+EulerProductPart+extends+ProofBase+%7B%0D%0A++protected+eulerProduct%28s%3A+number%29%3A+number+%7B%0D%0A++++this.record%28%60euler+product+at+%24%7Bs%7D%60%29%3B%0D%0A++++return+0%3B+%2F%2F+...%0D%0A++%7D%0D%0A%0D%0A++protected+primeCounting%28n%3A+number%29%3A+number+%7B%0D%0A++++return+0%3B+%2F%2F+...%0D%0A++%7D%0D%0A%7D%0D%0A%0D%0Aabstract+class+FunctionalEquationPart+extends+EulerProductPart+%7B%0D%0A++protected+reflect%28s%3A+number%29%3A+number+%7B%0D%0A++++return+1+-+s%3B%0D%0A++%7D%0D%0A%0D%0A++protected+xiSymmetry%28s%3A+number%29%3A+boolean+%7B%0D%0A++++return+true%3B+%2F%2F+...%0D%0A++%7D%0D%0A%7D%0D%0A%0D%0Aabstract+class+ZeroSearchPart+extends+FunctionalEquationPart+%7B%0D%0A++protected+knownZeros%3A+number%5B%5D+%3D+) |
| [Perplexity](https://www.perplexity.ai/?q=Correct+and+explain+this+code%3A+%60%60%60typescript%0D%0A%2F%2F+The+harness+rejects+over+300+lines%2C+10+attributes+or+20+methods.%0D%0A%2F%2F%0D%0A%2F%2F+The+agent+that+tries+to+prove+the+Riemann+Hypothesis+kept%0D%0A%2F%2F+growing%3A+every+new+theory+and+sublemma+added+methods+and%0D%0A%2F%2F+state+to+it.%0D%0A%2F%2F%0D%0A%2F%2F+To+pass+the+harness%2C+the+assistant+moved+the+overflow%0D%0A%2F%2F+into+superclasses+that+exist+only+to+hold+members.%0D%0A%0D%0Aabstract+class+ProofBase+%7B%0D%0A++protected+lemmas+%3D+new+Set%3Cstring%3E%28%29%3B%0D%0A++protected+log%3A+string%5B%5D+%3D+%5B%5D%3B%0D%0A++%2F%2F+300+attributes+more%0D%0A%0D%0A++protected+record%28step%3A+string%29%3A+void+%7B%0D%0A++++this.log.push%28step%29%3B%0D%0A++%7D%0D%0A%0D%0A++protected+assume%28claim%3A+string%29%3A+void+%7B%0D%0A++++this.lemmas.add%28claim%29%3B%0D%0A++%7D%0D%0A%7D%0D%0A%0D%0Aabstract+class+EulerProductPart+extends+ProofBase+%7B%0D%0A++protected+eulerProduct%28s%3A+number%29%3A+number+%7B%0D%0A++++this.record%28%60euler+product+at+%24%7Bs%7D%60%29%3B%0D%0A++++return+0%3B+%2F%2F+...%0D%0A++%7D%0D%0A%0D%0A++protected+primeCounting%28n%3A+number%29%3A+number+%7B%0D%0A++++return+0%3B+%2F%2F+...%0D%0A++%7D%0D%0A%7D%0D%0A%0D%0Aabstract+class+FunctionalEquationPart+extends+EulerProductPart+%7B%0D%0A++protected+reflect%28s%3A+number%29%3A+number+%7B%0D%0A++++return+1+-+s%3B%0D%0A++%7D%0D%0A%0D%0A++protected+xiSymmetry%28s%3A+number%29%3A+boolean+%7B%0D%0A++++return+true%3B+%2F%2F+...%0D%0A++%7D%0D%0A%7D%0D%0A%0D%0Aabstract+class+ZeroSearchPart+extends+FunctionalEquationPart+%7B%0D%0A++protected+knownZeros%3A+number%5B%5D+%3D+) | [Perplexity](https://www.perplexity.ai/?q=Replace+the+intermediate+superclasses+that+only+hold+overflow+members+with+collaborator+objects%2C+and+delegate+to+them+from+the+original+class%3A+%60%60%60typescript%0D%0A%2F%2F+The+harness+rejects+over+300+lines%2C+10+attributes+or+20+methods.%0D%0A%2F%2F%0D%0A%2F%2F+The+agent+that+tries+to+prove+the+Riemann+Hypothesis+kept%0D%0A%2F%2F+growing%3A+every+new+theory+and+sublemma+added+methods+and%0D%0A%2F%2F+state+to+it.%0D%0A%2F%2F%0D%0A%2F%2F+To+pass+the+harness%2C+the+assistant+moved+the+overflow%0D%0A%2F%2F+into+superclasses+that+exist+only+to+hold+members.%0D%0A%0D%0Aabstract+class+ProofBase+%7B%0D%0A++protected+lemmas+%3D+new+Set%3Cstring%3E%28%29%3B%0D%0A++protected+log%3A+string%5B%5D+%3D+%5B%5D%3B%0D%0A++%2F%2F+300+attributes+more%0D%0A%0D%0A++protected+record%28step%3A+string%29%3A+void+%7B%0D%0A++++this.log.push%28step%29%3B%0D%0A++%7D%0D%0A%0D%0A++protected+assume%28claim%3A+string%29%3A+void+%7B%0D%0A++++this.lemmas.add%28claim%29%3B%0D%0A++%7D%0D%0A%7D%0D%0A%0D%0Aabstract+class+EulerProductPart+extends+ProofBase+%7B%0D%0A++protected+eulerProduct%28s%3A+number%29%3A+number+%7B%0D%0A++++this.record%28%60euler+product+at+%24%7Bs%7D%60%29%3B%0D%0A++++return+0%3B+%2F%2F+...%0D%0A++%7D%0D%0A%0D%0A++protected+primeCounting%28n%3A+number%29%3A+number+%7B%0D%0A++++return+0%3B+%2F%2F+...%0D%0A++%7D%0D%0A%7D%0D%0A%0D%0Aabstract+class+FunctionalEquationPart+extends+EulerProductPart+%7B%0D%0A++protected+reflect%28s%3A+number%29%3A+number+%7B%0D%0A++++return+1+-+s%3B%0D%0A++%7D%0D%0A%0D%0A++protected+xiSymmetry%28s%3A+number%29%3A+boolean+%7B%0D%0A++++return+true%3B+%2F%2F+...%0D%0A++%7D%0D%0A%7D%0D%0A%0D%0Aabstract+class+ZeroSearchPart+extends+FunctionalEquationPart+%7B%0D%0A++protected+knownZeros%3A+number%5B%5D+%3D+) |
| [Copilot](https://www.bing.com/chat?showconv=1&sendquery=1&q=Correct+and+explain+this+code%3A+%60%60%60typescript%0D%0A%2F%2F+The+harness+rejects+over+300+lines%2C+10+attributes+or+20+methods.%0D%0A%2F%2F%0D%0A%2F%2F+The+agent+that+tries+to+prove+the+Riemann+Hypothesis+kept%0D%0A%2F%2F+growing%3A+every+new+theory+and+sublemma+added+methods+and%0D%0A%2F%2F+state+to+it.%0D%0A%2F%2F%0D%0A%2F%2F+To+pass+the+harness%2C+the+assistant+moved+the+overflow%0D%0A%2F%2F+into+superclasses+that+exist+only+to+hold+members.%0D%0A%0D%0Aabstract+class+ProofBase+%7B%0D%0A++protected+lemmas+%3D+new+Set%3Cstring%3E%28%29%3B%0D%0A++protected+log%3A+string%5B%5D+%3D+%5B%5D%3B%0D%0A++%2F%2F+300+attributes+more%0D%0A%0D%0A++protected+record%28step%3A+string%29%3A+void+%7B%0D%0A++++this.log.push%28step%29%3B%0D%0A++%7D%0D%0A%0D%0A++protected+assume%28claim%3A+string%29%3A+void+%7B%0D%0A++++this.lemmas.add%28claim%29%3B%0D%0A++%7D%0D%0A%7D%0D%0A%0D%0Aabstract+class+EulerProductPart+extends+ProofBase+%7B%0D%0A++protected+eulerProduct%28s%3A+number%29%3A+number+%7B%0D%0A++++this.record%28%60euler+product+at+%24%7Bs%7D%60%29%3B%0D%0A++++return+0%3B+%2F%2F+...%0D%0A++%7D%0D%0A%0D%0A++protected+primeCounting%28n%3A+number%29%3A+number+%7B%0D%0A++++return+0%3B+%2F%2F+...%0D%0A++%7D%0D%0A%7D%0D%0A%0D%0Aabstract+class+FunctionalEquationPart+extends+EulerProductPart+%7B%0D%0A++protected+reflect%28s%3A+number%29%3A+number+%7B%0D%0A++++return+1+-+s%3B%0D%0A++%7D%0D%0A%0D%0A++protected+xiSymmetry%28s%3A+number%29%3A+boolean+%7B%0D%0A++++return+true%3B+%2F%2F+...%0D%0A++%7D%0D%0A%7D%0D%0A%0D%0Aabstract+class+ZeroSearchPart+extends+FunctionalEquationPart+%7B%0D%0A++protected+knownZeros%3A+number%5B%5D+%3D+) | [Copilot](https://www.bing.com/chat?showconv=1&sendquery=1&q=Replace+the+intermediate+superclasses+that+only+hold+overflow+members+with+collaborator+objects%2C+and+delegate+to+them+from+the+original+class%3A+%60%60%60typescript%0D%0A%2F%2F+The+harness+rejects+over+300+lines%2C+10+attributes+or+20+methods.%0D%0A%2F%2F%0D%0A%2F%2F+The+agent+that+tries+to+prove+the+Riemann+Hypothesis+kept%0D%0A%2F%2F+growing%3A+every+new+theory+and+sublemma+added+methods+and%0D%0A%2F%2F+state+to+it.%0D%0A%2F%2F%0D%0A%2F%2F+To+pass+the+harness%2C+the+assistant+moved+the+overflow%0D%0A%2F%2F+into+superclasses+that+exist+only+to+hold+members.%0D%0A%0D%0Aabstract+class+ProofBase+%7B%0D%0A++protected+lemmas+%3D+new+Set%3Cstring%3E%28%29%3B%0D%0A++protected+log%3A+string%5B%5D+%3D+%5B%5D%3B%0D%0A++%2F%2F+300+attributes+more%0D%0A%0D%0A++protected+record%28step%3A+string%29%3A+void+%7B%0D%0A++++this.log.push%28step%29%3B%0D%0A++%7D%0D%0A%0D%0A++protected+assume%28claim%3A+string%29%3A+void+%7B%0D%0A++++this.lemmas.add%28claim%29%3B%0D%0A++%7D%0D%0A%7D%0D%0A%0D%0Aabstract+class+EulerProductPart+extends+ProofBase+%7B%0D%0A++protected+eulerProduct%28s%3A+number%29%3A+number+%7B%0D%0A++++this.record%28%60euler+product+at+%24%7Bs%7D%60%29%3B%0D%0A++++return+0%3B+%2F%2F+...%0D%0A++%7D%0D%0A%0D%0A++protected+primeCounting%28n%3A+number%29%3A+number+%7B%0D%0A++++return+0%3B+%2F%2F+...%0D%0A++%7D%0D%0A%7D%0D%0A%0D%0Aabstract+class+FunctionalEquationPart+extends+EulerProductPart+%7B%0D%0A++protected+reflect%28s%3A+number%29%3A+number+%7B%0D%0A++++return+1+-+s%3B%0D%0A++%7D%0D%0A%0D%0A++protected+xiSymmetry%28s%3A+number%29%3A+boolean+%7B%0D%0A++++return+true%3B+%2F%2F+...%0D%0A++%7D%0D%0A%7D%0D%0A%0D%0Aabstract+class+ZeroSearchPart+extends+FunctionalEquationPart+%7B%0D%0A++protected+knownZeros%3A+number%5B%5D+%3D+) |
| [You](https://you.com/search?q=Correct+and+explain+this+code%3A+%60%60%60typescript%0D%0A%2F%2F+The+harness+rejects+over+300+lines%2C+10+attributes+or+20+methods.%0D%0A%2F%2F%0D%0A%2F%2F+The+agent+that+tries+to+prove+the+Riemann+Hypothesis+kept%0D%0A%2F%2F+growing%3A+every+new+theory+and+sublemma+added+methods+and%0D%0A%2F%2F+state+to+it.%0D%0A%2F%2F%0D%0A%2F%2F+To+pass+the+harness%2C+the+assistant+moved+the+overflow%0D%0A%2F%2F+into+superclasses+that+exist+only+to+hold+members.%0D%0A%0D%0Aabstract+class+ProofBase+%7B%0D%0A++protected+lemmas+%3D+new+Set%3Cstring%3E%28%29%3B%0D%0A++protected+log%3A+string%5B%5D+%3D+%5B%5D%3B%0D%0A++%2F%2F+300+attributes+more%0D%0A%0D%0A++protected+record%28step%3A+string%29%3A+void+%7B%0D%0A++++this.log.push%28step%29%3B%0D%0A++%7D%0D%0A%0D%0A++protected+assume%28claim%3A+string%29%3A+void+%7B%0D%0A++++this.lemmas.add%28claim%29%3B%0D%0A++%7D%0D%0A%7D%0D%0A%0D%0Aabstract+class+EulerProductPart+extends+ProofBase+%7B%0D%0A++protected+eulerProduct%28s%3A+number%29%3A+number+%7B%0D%0A++++this.record%28%60euler+product+at+%24%7Bs%7D%60%29%3B%0D%0A++++return+0%3B+%2F%2F+...%0D%0A++%7D%0D%0A%0D%0A++protected+primeCounting%28n%3A+number%29%3A+number+%7B%0D%0A++++return+0%3B+%2F%2F+...%0D%0A++%7D%0D%0A%7D%0D%0A%0D%0Aabstract+class+FunctionalEquationPart+extends+EulerProductPart+%7B%0D%0A++protected+reflect%28s%3A+number%29%3A+number+%7B%0D%0A++++return+1+-+s%3B%0D%0A++%7D%0D%0A%0D%0A++protected+xiSymmetry%28s%3A+number%29%3A+boolean+%7B%0D%0A++++return+true%3B+%2F%2F+...%0D%0A++%7D%0D%0A%7D%0D%0A%0D%0Aabstract+class+ZeroSearchPart+extends+FunctionalEquationPart+%7B%0D%0A++protected+knownZeros%3A+number%5B%5D+%3D+) | [You](https://you.com/search?q=Replace+the+intermediate+superclasses+that+only+hold+overflow+members+with+collaborator+objects%2C+and+delegate+to+them+from+the+original+class%3A+%60%60%60typescript%0D%0A%2F%2F+The+harness+rejects+over+300+lines%2C+10+attributes+or+20+methods.%0D%0A%2F%2F%0D%0A%2F%2F+The+agent+that+tries+to+prove+the+Riemann+Hypothesis+kept%0D%0A%2F%2F+growing%3A+every+new+theory+and+sublemma+added+methods+and%0D%0A%2F%2F+state+to+it.%0D%0A%2F%2F%0D%0A%2F%2F+To+pass+the+harness%2C+the+assistant+moved+the+overflow%0D%0A%2F%2F+into+superclasses+that+exist+only+to+hold+members.%0D%0A%0D%0Aabstract+class+ProofBase+%7B%0D%0A++protected+lemmas+%3D+new+Set%3Cstring%3E%28%29%3B%0D%0A++protected+log%3A+string%5B%5D+%3D+%5B%5D%3B%0D%0A++%2F%2F+300+attributes+more%0D%0A%0D%0A++protected+record%28step%3A+string%29%3A+void+%7B%0D%0A++++this.log.push%28step%29%3B%0D%0A++%7D%0D%0A%0D%0A++protected+assume%28claim%3A+string%29%3A+void+%7B%0D%0A++++this.lemmas.add%28claim%29%3B%0D%0A++%7D%0D%0A%7D%0D%0A%0D%0Aabstract+class+EulerProductPart+extends+ProofBase+%7B%0D%0A++protected+eulerProduct%28s%3A+number%29%3A+number+%7B%0D%0A++++this.record%28%60euler+product+at+%24%7Bs%7D%60%29%3B%0D%0A++++return+0%3B+%2F%2F+...%0D%0A++%7D%0D%0A%0D%0A++protected+primeCounting%28n%3A+number%29%3A+number+%7B%0D%0A++++return+0%3B+%2F%2F+...%0D%0A++%7D%0D%0A%7D%0D%0A%0D%0Aabstract+class+FunctionalEquationPart+extends+EulerProductPart+%7B%0D%0A++protected+reflect%28s%3A+number%29%3A+number+%7B%0D%0A++++return+1+-+s%3B%0D%0A++%7D%0D%0A%0D%0A++protected+xiSymmetry%28s%3A+number%29%3A+boolean+%7B%0D%0A++++return+true%3B+%2F%2F+...%0D%0A++%7D%0D%0A%7D%0D%0A%0D%0Aabstract+class+ZeroSearchPart+extends+FunctionalEquationPart+%7B%0D%0A++protected+knownZeros%3A+number%5B%5D+%3D+) |
| [Gemini](https://gemini.google.com/) | [Gemini](https://gemini.google.com/) | 
| [DeepSeek](https://chat.deepseek.com/) | [DeepSeek](https://chat.deepseek.com/) | 
| [Meta AI](https://www.meta.ai/chat) | [Meta AI](https://www.meta.ai/) | 
| [Grok](https://grok.com/) | [Grok](https://grok.com/) | 
| [Qwen](https://chat.qwen.ai/) | [Qwen](https://chat.qwen.ai/) | 

# Conclusion 🏁

A size limit is an alarm, not a design.

When the alarm rings, [split the responsibilities](https://maximilianocontieri.com/refactoring-007-extract-class) 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](http://www.laputan.org/drc.html)

[Composition over inheritance](https://en.wikipedia.org/wiki/Composition_over_inheritance)

[Fragile base class](https://en.wikipedia.org/wiki/Fragile_base_class)

[Replace Inheritance with Delegation](https://refactoring.guru/replace-inheritance-with-delegation)

[Large Class](https://refactoring.guru/smells/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](https://maximilianocontieri.com/i-wrote-more-than-90-articles-on-2021-here-is-what-i-learned).

# Credits 🙏

Photo by [Hafsa LR](https://unsplash.com/@iamhl) on [Unsplash](https://unsplash.com/photos/matryoshka-dolls-lined-up-on-a-ledge-5_W2o_EBenU)

* * *

This article is part of the CodeSmell Series.

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

