Selecting a Replaceable Algorithm
A replaceable strategy gives several implementations the same role under one documented interface.
- Source
- Anbloq
- Language
- English
- Created
- Updated
- Chapters
- 2
- Reading time
- 1 min
In this article2 chapters
Choose a small example
A report can sort records by date or by title according to a caller setting. Supplying a key function may cover both strategies with the same sort implementation.
Use an object if the role carries verified state
A converter may keep a fixed translation table and several operations over it. A callable or an object can expose that behavior depending on what consumers actually need. Test the shared interface contract.[1]