Decide Builder

When to use the fluent Builder pattern vs constructors or factories.

attac-t f33b436 2 files · 2.7 KB Updated

File contents

Skill: Builder

"Many options. One fluent API."

The Decision

Use Builder when:

  • Object requires many optional parameters
  • Construction order matters
  • You want a fluent, readable API
  • Configuration is context-dependent

Use Constructor/Factory when:

  • Object is simple (few required params)
  • All params are mandatory
  • No variation in construction

The Heuristic

Ask: "Do I need to configure this object in multiple ways?"

  • Yes, many options → Builder
  • No, fixed construction → Constructor/Factory

The Quick Test

Scenario Use
5+ optional parameters Builder
Context-dependent defaults Builder
Method chaining improves readability Builder
Simple, mandatory params Constructor
Single creation path Factory

Real-World Examples

For concrete examples from Laravel, Spatie, and production code, see examples.md.

attac-t/the-foundry/tree/main/plugins/laravel-ddd/skills/decide-builder commit f33b436cdf

Frequently asked questions

npx skillmds@latest add attac-t/decide-builder