Strategy pattern: Transcoder example (Java flavour)

By | 22 June, 2014

This example is based on the declaration “Strategy pattern: Transcoder example

Strategy Pattern - TranscoderExample


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.

Execution result


Leave a Reply

Your email address will not be published. Required fields are marked *