Apply when encountering switch/if-else dispatch on entity type, designing entity systems, or refactoring toward extensibility. Provides registry-based dispatch, capability composition, and infrastructure-first patterns. Complements solid-architecture.
Refactors switch-based dispatch into extensible registry patterns for entity systems and plugin architectures.
npx claudepluginhub rbergman/dark-matter-marketplaceThis skill inherits all available tools. When active, it can use any tool Claude has access to.
Activate this skill when:
Separate data from behavior, dispatch via registry.
Entity = Pure Data (what it IS) + type discriminator
Definition = Bundled Behavior (what it DOES)
Registry = Type → Definition mapping (HOW to dispatch)
Switch statements scattered throughout codebase:
// Scattered in rendering.ts
switch (entity.type) {
case 'typeA': renderA(entity); break;
case 'typeB': renderB(entity); break;
}
// Scattered in update.ts
switch (entity.type) {
case 'typeA': updateA(entity); break;
case 'typeB': updateB(entity); break;
}
// Adding new type = edit N files
Single registry bundling all type-specific behavior:
// definitions.ts - ONE location for all type-specific code
const DEFS: Record<EntityType, Definition> = {
typeA: { render: renderA, update: updateA, ... },
typeB: { render: renderB, update: updateB, ... },
};
// Consumers dispatch generically
DEFS[entity.type].render(entity, ctx);
DEFS[entity.type].update(entity, dt);
// Adding new type = ONE registry entry, ZERO consumer changes
Definition interface with all operationsDEFS: Record<Type, Definition> registrygetDef(type): Definition helpergetDef(entity.type).operation()Record, Rust match)Not all entities need all behaviors. Deep inheritance or marker interfaces create coupling.
Optional capability configs with type guards:
interface Definition<T> {
// Required for all
create(): T;
render(): void;
// Optional capabilities - entities opt-in
collision?: CollisionConfig;
physics?: PhysicsConfig;
persistence?: PersistenceConfig;
}
// Type guard for safe access
function hasCollision(def): def is Definition & { collision: CollisionConfig } {
return def.collision !== undefined;
}
// Consumer checks capability
if (hasCollision(def)) {
collisionSystem.register(entity, def.collision);
}
BaseDefinition (create, render, layer)
↓ extends
DomainDefinition (domain-specific: AI, weapons)
↓ implemented by
ConcreteDefinitions (typeA, typeB, typeC)
// Base - works for any domain
interface EntityDefinition<TState, TType> {
type: TType;
create(pos): TState;
update?(entity, ctx): void;
render(entity, ctx): void;
collision?: CollisionConfig;
physics?: PhysicsConfig;
}
// Domain-specific extension
interface EnemyDefinition extends EntityDefinition<EnemyState, EnemyType> {
aiStrategy: AIStrategy;
weapons: WeaponConfig[];
}
// Another domain
interface PickupDefinition extends EntityDefinition<PickupState, PickupType> {
onCollect(collector): void;
floatAnimation: AnimationConfig;
}
Functions with many parameters, hard to extend.
Bundle related parameters into context objects:
// Bad - hard to extend
function update(entity, dt, playerPos, playerVel, gravity, time) { ... }
// Good - extensible
interface UpdateContext {
dt: number;
playerPos: Vec2;
playerVel: Vec2;
// Easy to add fields without breaking signatures
}
function update(entity, ctx: UpdateContext) { ... }
interface BaseContext { dt: number; }
interface AIContext extends BaseContext { playerPos: Vec2; threats: Entity[]; }
interface RenderContext { graphics: Graphics; screenPos: Vec2; scale: number; }
If writing a switch statement on entity type, infrastructure is missing.
Adding new type requires editing N files. Fix: Consolidate into registry.
SpecialEnemy extends FlyingEnemy extends Enemy extends Entity
Fix: Capability composition.
interface Entity {
weapon?: Weapon; // null checks everywhere
}
Fix: Separate capability with type guard.
Creating registry for 1 type. Fix: Wait for second type to validate pattern.
Definition with 50 fields for every possible behavior. Fix: Required base + optional capabilities.
Use language features to ensure all types are handled:
// TypeScript - Record requires all keys
const DEFS: Record<EntityType, Definition> = {
// Compiler error if type missing
};
// Helper for switch exhaustiveness
function assertNever(x: never): never {
throw new Error(`Unexpected: ${x}`);
}
When designing entity systems:
Applies Anthropic's official brand colors and typography to any sort of artifact that may benefit from having Anthropic's look-and-feel. Use it when brand colors or style guidelines, visual formatting, or company design standards apply.
Creating algorithmic art using p5.js with seeded randomness and interactive parameter exploration. Use this when users request creating art using code, generative art, algorithmic art, flow fields, or particle systems. Create original algorithmic art rather than copying existing artists' work to avoid copyright violations.
Create beautiful visual art in .png and .pdf documents using design philosophy. You should use this skill when the user asks to create a poster, piece of art, design, or other static piece. Create original visual designs, never copying existing artists' work to avoid copyright violations.