Command Palette

Search for a command to run...

Назад к скиллам
скилл № 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…

БесплатноБез исполняемых скриптов
openreachtechот openreachtech★ 17 звёзд на GitHub

Установить hoc-classes-principles в Claude Code и Claude Desktop

Зарегайся, чтобы установить скилл

Создай бесплатный аккаунт, чтобы открыть команду установки и сохранить скилл в библиотеку.

  • Открой команду установки в одну строку
  • Сохраняй скиллы в синхронизируемую библиотеку
  • Уведомления, когда скиллы обновляются
Зарегаться бесплатноУ меня уже есть аккаунт

Об этом скилле

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
Полный SKILL.md на GitHub

Разрешённые инструменты

Инструменты, которые скиллу разрешено вызывать.

Без ограничений — скилл может использовать любой инструмент.

FAQ

Что делает скилл 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 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.

Как установить скилл hoc-classes-principles?

Скопируй папку скилла в ~/.claude/skills (вкладка Claude Code выше делает это одной командой), либо поставь как плагин.

Скилл hoc-classes-principles запускает скрипты?

Нет, скилл состоит только из инструкций (SKILL.md), без исполняемых скриптов.

Похожие скиллы

Сравнить hoc-classes-principles с