Development Methods & Design

Strategy Pattern

English

Overview

A design pattern that extracts an algorithm as an interchangeable component that can be swapped out at runtime.

Details

By implementing logic that would otherwise be handled with conditional branches (if statements)—such as a discount calculation or a sorting method—as independent classes (strategies), you can add a new strategy without modifying existing code (the open/closed principle).

More Programming terms