- Scala Design Patterns.
- Ivan Nikolov
- 72字
- 2021-08-27 19:09:47
The strategy design pattern
The strategy design pattern allows algorithms to be selected at runtime. It defines a family of interchangeable encapsulated algorithms and exposes a common interface to the client. Which algorithm is chosen could depend on various factors that are determined while the application runs. In Scala, we can simply pass a function as a parameter to a method, and depending on the function, a different action will be performed.