/harness-claude:gof-decorator-patternfrom harness-claude
Attaches additional behavior to objects at runtime by wrapping them in decorator objects. Provides TypeScript examples for both structural and function-based decorators.
Claude never picks this skill on its own
Its frontmatter has no description. Without a description, Claude Code leaves it out of the list Claude chooses from. Typing /harness-claude:gof-decorator-pattern still runs it.
What the skill costs in Claude's context, stage by stage
No description Claude Code can read, so Claude's list leaves it out: only you can start it.
SKILL.md joins the conversation and stays.
Attach additional behavior to objects at runtime by wrapping them in decorator objects.
Classic structural decorator:
// Component interface
interface DataSource {
write(data: string): Promise<void>;
read(): Promise<string>;
}
// Concrete component
class FileDataSource implements DataSource {
constructor(private readonly path: string) {}
async write(data: string): Promise<void> {
// Write to file
console.log(`Writing to ${this.path}: ${data}`);
}
async read(): Promise<string> {
// Read from file
return `data from ${this.path}`;
}
}
// Base decorator — implements the interface and wraps a component
abstract class DataSourceDecorator implements DataSource {
constructor(protected readonly wrapped: DataSource) {}
async write(data: string): Promise<void> {
return this.wrapped.write(data);
}
async read(): Promise<string> {
return this.wrapped.read();
}
}
// Concrete decorator: encryption
class EncryptionDecorator extends DataSourceDecorator {
async write(data: string): Promise<void> {
const encrypted = Buffer.from(data).toString('base64'); // simplified
await this.wrapped.write(encrypted);
}
async read(): Promise<string> {
const data = await this.wrapped.read();
return Buffer.from(data, 'base64').toString('utf8'); // simplified
}
}
// Concrete decorator: compression
class CompressionDecorator extends DataSourceDecorator {
async write(data: string): Promise<void> {
const compressed = `[compressed:${data}]`; // simplified
await this.wrapped.write(compressed);
}
async read(): Promise<string> {
const data = await this.wrapped.read();
return data.replace(/^\[compressed:/, '').replace(/\]$/, '');
}
}
// Stack decorators in any order
const source: DataSource = new CompressionDecorator(
new EncryptionDecorator(new FileDataSource('/data/users.dat'))
);
await source.write('hello world');
Function-based decorator (idiomatic TypeScript for async functions):
type AsyncFn<T extends unknown[], R> = (...args: T) => Promise<R>;
// Retry decorator
function withRetry<T extends unknown[], R>(
fn: AsyncFn<T, R>,
maxAttempts = 3,
delayMs = 500
): AsyncFn<T, R> {
return async (...args: T): Promise<R> => {
let lastError: Error;
for (let attempt = 1; attempt <= maxAttempts; attempt++) {
try {
return await fn(...args);
} catch (err) {
lastError = err as Error;
if (attempt < maxAttempts) {
await new Promise((r) => setTimeout(r, delayMs * attempt));
}
}
}
throw lastError!;
};
}
// Cache decorator
function withCache<T extends unknown[], R>(fn: AsyncFn<T, R>, ttlMs = 60_000): AsyncFn<T, R> {
const cache = new Map<string, { value: R; expiresAt: number }>();
return async (...args: T): Promise<R> => {
const key = JSON.stringify(args);
const cached = cache.get(key);
if (cached && Date.now() < cached.expiresAt) return cached.value;
const value = await fn(...args);
cache.set(key, { value, expiresAt: Date.now() + ttlMs });
return value;
};
}
// Compose decorators
const fetchUser = async (id: string): Promise<User> => {
return db.users.findOneOrFail(id);
};
const robustFetchUser = withCache(withRetry(fetchUser, 3), 30_000);
Decorator vs. Proxy: Both wrap an object. The Decorator adds behavior; the Proxy controls access. In practice the implementation is similar — the distinction is intent. Use Decorator for feature stacking (logging, caching), use Proxy for access control (authorization, lazy loading).
TypeScript class decorators vs. GOF Decorator pattern: TypeScript's @Decorator syntax is a different mechanism (metaprogramming on class metadata). The GOF Decorator is a runtime object-wrapping pattern. The GOF pattern works without experimentalDecorators and is preferred for production code.
Anti-patterns:
Middleware pipeline (alternative for many cross-cutting concerns):
type Middleware<T> = (value: T, next: () => Promise<T>) => Promise<T>;
async function pipeline<T>(value: T, middlewares: Middleware<T>[]): Promise<T> {
const run = async (index: number): Promise<T> => {
if (index >= middlewares.length) return value;
return middlewares[index](value, () => run(index + 1));
};
return run(0);
}
refactoring.guru/design-patterns/decorator
What SKILL.md sets; muted values are Claude Code's defaults
npx claudepluginhub intense-visions/harness-engineering --plugin harness-claudeRead when SKILL.md points to them.
793 skills in this plugin
/a11y-aria-patternsARIA Patterns> Apply ARIA roles, states, and properties correctly to enhance assistive technology support for custom widgets/a11y-color-contrastColor Contrast and Color Independence> Ensure sufficient color contrast ratios and never use color as the sole means of conveying information/a11y-form-patternsAccessible Form Patterns> Build accessible forms with proper labeling, grouped controls, inline validation, and clear error communicationOther plugins' skills for the same job