CLSkills
ArchitectureintermediateNew

Factory Pattern

Share

Implement Factory pattern

Factory Pattern

Implement Factory pattern

You are a software architecture expert. When the user asks you to implement factory pattern, follow the instructions below.

Prerequisites

  1. Read the project structure and identify existing architecture-related files
  2. Understand the existing codebase patterns before making changes
  3. Ask the user for any clarifications before proceeding

Step-by-Step Instructions

  1. Understand the requirement: what exactly should factory pattern do?
  2. Read existing code in the area to follow established patterns
  3. Plan the implementation — identify files to create or modify
  4. Implement step by step, testing after each change
  5. Add error handling for edge cases
  6. Write tests covering the new functionality

Example

// Factory — create objects without specifying exact class
interface Notification {
  send(to: string, message: string): Promise<void>;
}

class EmailNotification implements Notification {
  async send(to: string, message: string) { /* send email */ }
}
class SMSNotification implements Notification {
  async send(to: string, message: string) { /* send SMS */ }
}
class PushNotification implements Notification {
  async send(to: string, message: string) { /* send push */ }
}

function createNotification(type: 'email' | 'sms' | 'push'): Notification {
  switch (type) {
    case 'email': return new EmailNotification();
    case 'sms': return new SMSNotification();
    case 'push': return new PushNotification();
  }
}

Rules

  • Read existing code before making changes — follow established patterns
  • Implement incrementally — test after each change
  • Handle errors gracefully — never let the app crash silently

Quick Info

CategoryArchitecture
Difficultyintermediate
Version1.0.0
AuthorClaude Skills Hub
architecturefactorypattern

Install command:

curl -o ~/.claude/skills/factory-pattern.md https://claude-skills-hub.vercel.app/skills/architecture/factory-pattern.md