Software Engineer
mediumstrategy-and-factory-patterns

When would you use the Strategy and Factory design patterns?

Answer

**Strategy**: choose behavior at runtime (e.g., different pricing algorithms). It reduces `if/else` chains and supports extension. **Factory**: centralize object creation (e.g., create different `PaymentProvider` implementations). It hides construction details and supports DI. In interviews, emphasize the goal: reduce coupling, improve extensibility, and keep code open for new behaviors without large rewrites.

Related Topics

Design PatternsSoftware DesignOOP