Return to site

DESIGN PATTERN: Strategy

· pattern

The _____ Pattern is a design pattern that defines interchangeable algorithms, encapsulates each one, and allows the client to choose the appropriate algorithm at runtime without altering its structure.

* Pipeline

* Chain of Responsibility

* Strategy

* State

#design #pattern #programming #software

https://www.udemy.com/course/master-software-design-patterns-questions-and-full-answers/?referralCode=D6366BB829DB93970447

The Strategy Pattern is a behavioral design pattern in software development that defines a family of interchangeable algorithms, encapsulates each one, and makes them interchangeable.

It allows a client to choose the appropriate algorithm at runtime without altering its structure.

broken image

1) Context:

The Context is the class that contains a reference to a Strategy object and can switch between different strategies.

It usually represents the client or the entity that uses the strategy.

2) Strategy:

The Strategy is an interface or abstract class that defines a common method or set of methods that concrete strategy classes must implement.

Each concrete strategy represents a specific algorithm or behavior.

3) Concrete Strategy:

Concrete Strategy classes are the implementations of the Strategy interface.

Each one provides a different algorithm or behavior that can be used by the Context.

The Strategy Pattern is valuable in situations where you need to switch between different algorithms or behaviors dynamically.

It promotes flexibility, maintainability, and the ability to add new strategies without changing existing code.

It's commonly used in various areas, such as sorting algorithms, payment processing, and behavior customization in software systems.