factory-pattern-applied

Identify and implement DDD Factory patterns for complex object creation.

10|2|Updated Feb 5, 2026
One-click install
npx skills add https://github.com/pwyczes/ddd-ai-skills-applied --skill factory-pattern-applied
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: factory-pattern-applied
Source: https://github.com/pwyczes/ddd-ai-skills-applied/tree/main/factory-pattern-applied
Command: npx skills add https://github.com/pwyczes/ddd-ai-skills-applied --skill factory-pattern-applied

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve?

This Skill helps you manage and implement the Factory pattern, a design pattern that encapsulates complex object creation logic, making your code cleaner and more maintainable.

Core Features & Use Cases

  • Identify Opportunities: Recognizes situations where a Factory pattern is beneficial, such as complex constructors, scattered creation logic, or when external dependencies are required for object instantiation.
  • Guide Implementation: Provides clear patterns for creating static factory methods or dedicated factory classes.
  • Use Case: When creating an Order object requires fetching pricing information and checking inventory, a Factory can handle these dependencies, ensuring the Order object is created in a valid state.

Quick Start

Apply the factory-pattern-applied skill to refactor the complex constructor of the ShipmentLabel class.

Frequently Asked Questions about factory-pattern-applied

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
When do I need a factory pattern for object creation?

Use a factory pattern when constructors become complex, creation logic is scattered across client code, or external dependencies like pricing and inventory checks are needed to instantiate a valid domain object.

How do I refactor a complex constructor using the DDD factory pattern?

Refactor complex constructors by extracting the instantiation logic into static factory methods or dedicated factory classes, encapsulating dependencies to ensure the domain object is created in a valid, well-formed state.

What is the best way to handle external dependencies during domain object creation?

Encapsulate external dependencies within a dedicated Factory class or static factory method to handle data fetching and invariant validation, ensuring the domain object is returned in a valid state.

Does the factory pattern help with multiple overloaded constructors?

Yes, the factory pattern replaces multiple overloaded constructors with explicitly named static factory methods, clarifying object instantiation intent and simplifying client code that creates domain objects.

Can I use a static factory method instead of a dedicated factory class for domain objects?

Yes, static factory methods work for simpler instantiation, but dedicated factory classes are better when complex external dependencies or multiple creation steps are needed to satisfy domain invariants and simplify client code.

Why does scattered object creation logic cause maintenance issues?

Scattered creation logic causes maintenance issues by spreading invariant validation and dependency resolution across client code, making it difficult to ensure domain objects are consistently instantiated in a valid state.