🎉 Hooray! After 3 years of work, I've finally released the ebook on design patterns! Check it out »
Strategy

Strategy in Swift

Strategy is a behavioral design pattern that turns a set of behaviors into objects and makes them interchangeable inside original context object.

The original object, called context, holds a reference to a strategy object and delegates it executing the behavior. In order to change the way the context performs its work, other objects may replace currently linked strategy object with another one.

Learn more about Strategy

Usage of the pattern in Swift

Complexity:

Popularity:

Usage examples: The Strategy pattern is very common in Swift code. It’s often used in various frameworks to provide users a way to change the behavior of a class without extending it.

Identification: Strategy pattern can be recognized by a method that lets nested object do the actual work, as well as the setter that allows replacing that object with a different one.

Strategy in Other Languages

Strategy in Java Strategy in C# Strategy in PHP Strategy in Python Strategy in Ruby Strategy in TypeScript