This example is based on the declaration “Strategy pattern: Transcoder example”
- Sources: GIST
About the code
- TranscondigTextService: class with “context” role. This class is interested of change its behavior in order to produce diferents kind of output codes
- TranscondigTextService(strategy: Strategy): constructor with initial strategy injection.
- transcoder: state that store the the reference to the strategy used (plugable object).
- TranscoderStrategy: abstract declaration for the strategy
- transcode(message:String): public interface for strategy invocation.
- ASSCIDecimalCodeTranscoderStrategy: concrete implementation for ASSCII code output.
- BrailleTranscoderStrategy: concrete implementation for Braille output
- MorseTranscoderStrategy: concrete implementation for Morse output
TranscoderStrategy has been implemented by interface not as abstract class because there is not default state or behavior needed.
TranscodingTextService is using the behavior injected by constructor...
Meessage to translate: to ASCII Code
TranscodingTextService can change its behavior dinamicaly by setter...
Meessage to translate: to Brailling
Meessage to translate: to Encrypt code
Meessage to translate: to Morse Code
- Implementation Patterns, chapter 5, Class (by Kent Beck)