skills/design-patterns/structurals/pattern-flyweight/SKILL.md
Teaches and applies the Flyweight structural design pattern — minimizing memory usage by sharing common state between multiple fine-grained objects. Trigger: When dealing with large numbers of similar objects consuming too much memory.
npx skillsauth add johnnystefan/test-saas-business pattern-flyweightInstall this skill globally with one command. Works with Claude Code, Cursor, and Windsurf.
3 of 9 scanners reported clean
Some scanners were skipped, did not run, or reported a non-clean status. Review each row below.
Minimizes memory usage by sharing common parts of state between multiple objects instead of keeping all data in each object.
// Shared state (Flyweight)
class TreeType {
constructor(
private name: string,
private color: string,
) {}
draw(x: number, y: number) {
/* Draw logic */
}
}
// Factory manages sharing
class TreeFactory {
private static types: Map<string, TreeType> = new Map();
static getTreeType(name: string, color: string) {
let type = this.types.get(name + color);
if (!type) {
type = new TreeType(name, color);
this.types.set(name + color, type);
}
return type;
}
}
// Context stores unique state
class Tree {
constructor(
private x: number,
private y: number,
private type: TreeType,
) {}
draw() {
this.type.draw(this.x, this.y);
}
}
tools
Zustand 5 state management patterns. Trigger: When implementing client-side state with Zustand (stores, selectors, persist middleware, slices).
databases
Zod 4 schema validation patterns. Trigger: When creating or updating Zod v4 schemas for validation/parsing (forms, request payloads, adapters), including v3 -> v4 migration patterns.
development
Vitest unit testing patterns with React Testing Library. Trigger: When writing unit tests for React components, hooks, or utilities.
tools
Vite 8 (Rolldown-powered) build tool configuration, plugin API, SSR, and migration guide. Trigger: When working with vite.config.ts, Vite plugins, building libraries, or SSR apps with Vite.