Js abstract factory pattern

From Intense-Visions/harness-engineering · View interactive version

Js abstract factory pattern is an AI agent skill from the GitHub repository Intense-Visions/harness-engineering. > Create families of related objects without specifying their concrete classes

How to use this skill

Skill file

JS Abstract Factory Pattern

Create families of related objects without specifying their concrete classes

When to Use

Instructions

  1. Define an abstract factory interface listing all creation methods.
  2. Implement one concrete factory per product family.
  3. Clients use only the abstract factory interface — they never instantiate concrete products directly.
  4. Switch families by swapping the factory instance, not by changing client code.
// Abstract Factory (interface defined by convention)
class LightThemeFactory {
  createButton() {
    return { color: 'white', text: 'dark' };
  }
  createInput() {
    return { background: '#f0f0f0', border: '1px solid #ccc' };
  }
}

class DarkThemeFactory {
  createButton() {
    return { color: '#333', text: 'white' };
  }
  createInput() {
    return { background: '#222', border: '1px solid #555' };
  }
}

function renderUI(factory) {
  const button = factory.createButton();
  const input = factory.createInput();
  return { button, input };
}

const ui = renderUI(new DarkThemeFactory());

Details

The Abstract Factory is a creational pattern that sits one level of abstraction above the Factory pattern. Where a Factory creates one type of product, an Abstract Factory creates an entire suite of related products.

Trade-offs:

When NOT to use:

Source

https://patterns.dev/javascript/abstract-factory-pattern

Process

  1. Read the instructions and examples in this document.
  2. Apply the patterns to your implementation, adapting to your specific context.
  3. Verify your implementation against the details and edge cases listed above.

Harness Integration

Success Criteria

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.