Category Archives: Strategy

We’re going to create a little service in order to transform from text message to the different kind of code: ASCII code: represent the text as the secuence of numeric codes of the character of the message Braille code Morse code But we’d like: At creation time of the service: set up the code… Read More »

This example is based on the declaration “Strategy pattern: Transcoder example“ Sources JS Bin About the code Based on as commented with generic example: TrancoderStrategy Declaration by prototype property The default behavior throw an exception in order to force subclasses to implement thesse methods

1

2

3

TranscoderStrategy.prototype.transcode=function(message){

thrownewError('TranscoderStrategy#transcode needs to be overridden.');

};

1

2

3

TranscoderStrategy.prototype.setTranscoder=function(){

thrownewError('TranscoderStrategy#setTranscoder needs to be overridden.');

This example is based on the declaration “Strategy pattern: Transcoder example” Source: 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… Read More »