The strategy pattern can be employed when one thing can happen in many different ways. It's where one action (routing, encryption, file storage) has the same set of actions, even if you do them in different ways. It's a useful tool to [[Refactor]] code For example: * You can encrypt a file, and decrypt a file * You can use AES, Swordfish, etc... Instead of selecting the type of encryption with an if statement: 1. Define a common interface between the operations 2. Create a concrete class implementing that interface for each type of e.g. Encryption So you would have an AESEncryptor class and a SwordfishEncryptor class that implements the functionality, behind an IEncryptor interface. This [[Refactor#Coupling|decouples]] code from it's implementation and instead allows it to take any sort of encryption. > [!tip] Hot Tip > You can also use Anonymous Functions / Lambdas for this purpose instead of creating a concrete implementation, especially if that interface would be one function, if this makes sense. # References