Factory Pattern
Teaches the factory pattern for flexible object creation. Use when you need to create objects dynamically without using the new keyword or when object creation logic should be centralized.
Install
npx skills add PatternsDev/skills --skill factory-patterngit clone --depth 1 https://github.com/PatternsDev/skills.git /tmp/skills
mkdir -p ~/.claude/skills
cp -r /tmp/skills/javascript/factory-pattern ~/.claude/skills/factory-patternPersonal skills live in ~/.claude/skills. Use .claude/skills in a project folder to share a skill with your team.
From the SKILL.md
# Factory Pattern
With the factory pattern we can use **factory functions** in order to create new objects. A function is a factory function when it returns a new object without the use of the `new` keyword!
Say that we need many users for our application. We can create new users with a `firstName`, `lastName`, and `email` property. The factory function adds a `fullName` property to the newly created object as well, which returns the `firstName` and the `lastName`.
## When to Use
- Use this when you need to create multiple objects that share the same properties
- This is helpful when object creation depends on a certain environment or configuration
## When NOT to Use
- For simple objects where a plain object literal suffices — a factory adds unnecessary indirection
- When class constructors are the established convention in your project and the team expects `new`
- When there's no conditional logic or configuration driving object creation
## Instructions
- Use factory functions to return custom objects based on current environment or user-specific configuration
- Prefer ES6 arrow functions for concise factory function definitions
- Consider using class constructors instead when memory efficiency matters, as instances share prototype methods
## Details
```js
const createUser = ({ firstName, lastName, email }) => ({
firstName,
lastName,
email,
fullName() {
return `${this.firstName} ${this.lastName}`;
},
});
```Details
- Skill name
factory-pattern- Repository
- PatternsDev/skills
- Path
javascript/factory-pattern/SKILL.md- Repo updated
- 15 April 2026
FAQ
What does the Factory Pattern skill do?
Teaches the factory pattern for flexible object creation. Use when you need to create objects dynamically without using the new keyword or when object creation logic should be centralized.
How do I install the Factory Pattern skill?
skills CLI (Claude Code, Cursor, Codex and more): npx skills add PatternsDev/skills --skill factory-pattern. Skills go in ~/.claude/skills (personal) or .claude/skills (project), and Claude loads them automatically when a task matches the description.
Is Factory Pattern popular?
It lives in PatternsDev/skills, which has 259 GitHub stars and 28 forks.
Related skills
AI UI Patterns
259PatternsDev/skills
Teaches design patterns for building AI-powered React interfaces. Use when creating chatbots, intelligent assistants, streaming UIs, or any AI-driven user experience in React.
Async Components
259PatternsDev/skills
Teaches async component loading in Vue for performance optimization. Use when you have heavy components that aren't needed on initial render and can be loaded on demand.
Bundle Splitting
259PatternsDev/skills
Teaches bundle splitting techniques for web performance. Use when your application has a large JavaScript bundle that affects load times or when you need to reduce FCP/LCP.
Flyweight Pattern
259PatternsDev/skills
Teaches the flyweight pattern for memory optimization. Use when your application creates large numbers of similar objects and memory consumption is a concern.
Dynamic Import
259PatternsDev/skills
Teaches dynamic import() for on-demand code loading. Use when you need to reduce initial bundle size by lazily loading modules that aren't required at startup.
Import on Interaction
259PatternsDev/skills
Teaches interaction-based lazy loading for non-critical resources. Use when you have heavy components or libraries that are only needed after user interaction like clicks, hovers, or form input.
Browse the most popular Claude skills, all software development skills, or write your own with the skills generator.