Command Palette

Search for a command to run...

Back to skills
skill № 33958

hoc-classes-principles

Principles of class design — what a class has to hold to exist at all, and the premises the other class conventions rest on. Use when deciding whether…

FreeNo executable scripts
openreachtechby openreachtech★ 17 GitHub stars

Install hoc-classes-principles in Claude Code & Claude Desktop

Sign up to install this skill

Create a free account to reveal the install command and save the skill to your library.

  • Reveal the one-line install command
  • Save skills to your synced library
  • Get notified when skills update
Sign up freeI already have an account

About this skill

Classes: Principles

This summarizes the principles for class property declaration and design.

Core principle: Do not create classes without properties

  • A class must hold at least one instance property.
  • What the prohibition covers — static-only classes and classes without properties — and its exceptions and reasons belong to /hoc-classes-prohibits. This skill takes it as the core principle and builds the surrounding design conventions on top of it.

The five points of the system (a bundle of premises)

  1. Deep immutability — Do not reassign after construction; keep nested values (e.g. instances of other immutable classes) immutable too. The collection types Array / Set are not deep-frozen, because elements are added to them: while the collection is assembled, or at the tail of a queue. The reasons are that "the set of retained items" is premised on being treated as equal regardless of count, and that building supports the Builder Pattern, whose editing period runs until #buildXxxx() is called. How a collection's value may be used belongs to /hoc-properties, and why Map gives way to WeakMap to /hoc-prohibit-native-features.
  2. Property = a constructor argument of the same name — Every property that stores a value is passed as a constructor argument of the same name. This makes the set of property names a class occupies appear in the constructor signature itself, so hidden fields cannot exist in principle.
  3. Constructor-only — Only this.xxx = xxx inside the constructor counts as a property (see "Definition of 'property'" below).
  4. Treat references as the contract — The published API references fix the public surface. Direct access to a member not in the references is "undocumented = outside the contract," and breaking after coupling to it is the caller's responsibility. This is the stance that "reaching for a member outside the contract is the same as throwing a microwave at a beast" — a use outside the contract is not the designer's responsibility.
  5. Enumerating instances is prohibited — Enumerating a class instance that has behavior and invariants via Object.keys / Object.entries / for...in / spread {...instance} / Object.assign is treated as hack code. It is a category error that treats a behavior-bearing object as a POJO/dictionary, and a clearly bad design practice that drops the prototype (methods) to make a degraded copy.

Definition of "property"

  • Only this.xxx = xxx inside the constructor counts as a property.
  • Do not use class fields (x = 1) or private fields (#x = 1).

Reasons:

  • Single manifest — Anyone who wants to know "what does this class hold" reads only one place, the constructor (and its argument signature). If class fields are allowed, then even adding a member-ordering rule of "fields go first" still leaves two places to read: the leading field group and the computed this.x =. The real ground for going as far as prohibition is not "scattered and hard to find" but that it guarantees "strictly one location" (if it were merely "hard to find," an ordering rule would suffice, and someone would point that out).
  • Linear, clear initialization order — Class fields have the semantics of being initialized "right after super(), before the constructor body," which breeds bugs where super() and field initialization interleave under inheritance. Constructor-only avoids this structurally.
  • Eliminates split-brain — Using class fields together with the constructor falls into a double declaration of "default in a field / overridden in the constructor from an argument." The following is a property declared twice, with the field initializer killed by the constructor override — a clearly bad design practice.
// NG: mixing default + override (split-brain)
class Foo {
  x = 1              // default declaration
  constructor (x) {
    if (x !== undefined) {
      this.x = x     // override; the field initializer dies
    }
  }
}

Handling of static fields

  • static fields (static X = ...) may be used. The prohibition on class fields and private fields is a convention about instance properties, and static fields are out of its scope.
  • However, static #X (the static form of native private) is not used — see /hoc-prohibit-native-features.

This is because none of the three grounds for the prohibition apply to static.

  • Single manifest — What the manifest answers is "what does an instance of this class hold." A static field is not held by any instance, so it does not damage the at-a-glance completeness of the constructor signature. And since no declaration site exists outside the class body, "strictly one location" is already satisfied the moment it is written as static.
  • Initialization order — static fields are initialized in source order at class-definition time, so no problem arises from the interplay of super() an
Full SKILL.md on GitHub

Allowed tools

Tools this skill is permitted to call.

No restriction — this skill can use any tool.

FAQ

What does the hoc-classes-principles skill do?

Principles of class design — what a class has to hold to exist at all, and the premises the other class conventions rest on. Use when deciding whether something should be a class, when reaching for a class field or a plain object, or when the reason behind a class convention is in question. Native features the system does not use belong to the native-feature prohibition convention; specific prohibitions, to the class prohibitions convention; member order, to the class notation convention.

How do I install the hoc-classes-principles skill?

Copy the skill folder into ~/.claude/skills (the Claude Code tab above does this in one command), or install it as a plugin.

Does the hoc-classes-principles skill run scripts?

No, this skill is instructions only (SKILL.md) with no executable scripts.

Related skills

Compare hoc-classes-principles with