Multiple choice general knowledge math & puzzles

This Design Pattern define a family of algorithms, encapsulate each one and make them interchangeable

  1. Bridge

  2. Chain of Responsibility

  3. Template

  4. Strategy

Reveal answer Fill a bubble to check yourself
D Correct answer
Explanation

The Strategy pattern is defined as a family of algorithms, encapsulated separately, and made interchangeable. The Bridge pattern separates abstraction from implementation, Chain of Responsibility passes requests along a chain, and Template Method defines an algorithm's skeleton with steps that can be customized.

AI explanation

This is the textbook definition of the Strategy design pattern from the Gang of Four: it defines a family of interchangeable algorithms, encapsulates each one in its own class, and lets the algorithm vary independently of the clients that use it (e.g., swapping sorting or payment strategies at runtime). Template Method also involves algorithms but fixes the skeleton in a base class with steps overridden by subclasses (not fully interchangeable objects). Chain of Responsibility passes a request along a chain of handlers, and Bridge decouples abstraction from implementation -- neither matches 'family of interchangeable algorithms.'