Design Patterns interview question · Most asked
What is an anti-pattern? Name a few common ones.
Summary
An anti-pattern is a common response to a recurring problem that looks reasonable but usually causes more harm than good. Common ones: the god object, singleton used as a global variable, service locator, golden hammer (one favourite solution for everything), speculative generality, copy-paste programming and the anemic domain model.
Longer Answer
Recognising them matters as much as knowing patterns: a 3,000-line OrderManager (god object) or container.get() calls inside business classes (service locator) are more common than missing patterns. Each has a known remedy: split by responsibility, inject dependencies, start from the problem, wait for the second case.
Key Points
- Looks right, causes harm.
- God object, singleton-as-global, service locator.
- Golden hammer, speculative generality.
- Each has a known remedy.
Deep dive: Design Patterns, Explained Simply: Anti-Patterns and Over-Engineering
Explanation
What interviewers look for
Several correct examples with remedies.
Follow-up questions
- Which anti-pattern have you had to fix, and how?
More most-asked Design Patterns questions
- What problem does the Builder pattern solve? Show an example.
- Explain the SOLID principles.
- What is a design pattern, and why are they useful?
- What is the difference between dependency inversion, dependency injection and inversion of control?
- Why is composition often preferred over inheritance?
- What is dependency injection, and what forms does it take?
- Explain the Factory Method pattern and how it differs from a simple factory.
- How do you implement a Singleton, and why is it often considered an anti-pattern?