Hoc classes prohibits

From openreachtech/hora-skills-ort-core · View interactive version

Hoc classes prohibits is an AI agent skill from the GitHub repository openreachtech/hora-skills-ort-core. Convention on what a class definition may not be. Use when deciding whether a class should exist, or when reviewing one that holds no state. The principles these prohibitions rest on belong to the class design principles convention.

How to use this skill

Skill file

Classes: Prohibits

This summarizes prohibitions in class definitions.

Static-only classes are prohibited

Exception:

Reasons:

(1) A class is the place where "state-dependent behavior" is defined

(2) It hinders polymorphism

(3) Static methods should be placed where the responsibility belongs

base class. Expressing it through inheritance makes the location of responsibility clearer.

(4) It invites argument forwarding

// NG: static-only (beta is forwarded around by firstMethod)
class StaticOnlyClass {
  static entryPointMethod ({ alpha, beta }) {
    return { first: this.firstMethod({ alpha, beta }) }
  }

  static firstMethod ({ alpha, beta }) {
    return alpha
      + this.secondMethod({ beta })
  }

  static secondMethod ({ beta }) {
    return beta * 100
  }
}

// OK: instance class (arguments held as properties)
class InstanceClass {
  constructor ({ alpha, beta }) {
    this.alpha = alpha
    this.beta = beta
  }

  static create (params) {
    return new this(params)
  }

  entryPointMethod () {
    return { first: this.firstMethod() }
  }

  firstMethod () {
    return this.alpha
      + this.secondMethod()
  }

  secondMethod () {
    return this.beta * 100
  }
}

(5) It increases the cost of rewriting

(6) It increases review cost

Do not create classes without properties

Exception:

hard-code.** A base can look stateless because what it should have held was written into each

derived class instead — most visibly as one member every derived class overrides to return a

constant of its own. That constant is the base's property: it varies by derived class, which

is what a property is for, and the override exists only because the property is missing.

derived classes lose the member entirely. Measured on one such base: two derived classes each

overrode a member to return a fixed value; the value became a constructor argument of the

base, and both overrides went with it.

Reason:

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.