← ClaudeAtlas

code-patternslisted

Common code patterns and best practices reference for quick lookup
aiskillstore/marketplace · ★ 329 · AI & Automation · score 79
Install: claude install-skill aiskillstore/marketplace
# Code Patterns Reference Quick reference for common patterns. Use these as starting points, not rigid templates. ## Creational Patterns ### Factory ```typescript // When: Creating objects without specifying exact class interface Product { use(): void } class ConcreteProductA implements Product { use() { console.log('Using A') } } class ProductFactory { static create(type: string): Product { const products = { a: ConcreteProductA }; return new products[type](); } } ``` ### Builder ```typescript // When: Complex object construction with many optional params class QueryBuilder { private query = { select: '*', from: '', where: [] }; select(fields: string) { this.query.select = fields; return this; } from(table: string) { this.query.from = table; return this; } where(condition: string) { this.query.where.push(condition); return this; } build() { return this.query; } } // Usage const query = new QueryBuilder() .select('name, email') .from('users') .where('active = true') .build(); ``` ### Singleton ```typescript // When: Exactly one instance needed (use sparingly!) class Database { private static instance: Database; private constructor() {} static getInstance(): Database { if (!Database.instance) { Database.instance = new Database(); } return Database.instance; } } ``` ## Structural Patterns ### Adapter ```typescript // When: Making incompatible interfaces work together interface ModernLogger { log(msg: string):