Implementation
 
  1.     Defining the Strategy and Context interfaces

  2.     See collaborations
        1) In this case you might pass data that concrete strategy doesn't need
        2) & 3) Context must specify a more elaborate interface which increases
        coupling betweem the two classes
  3.     Strategies as template parameters

  4.  

     

       template <class Astrategy>
        class Context {
        void Operation() { theStrategy.DoAlgorithm(); }

        private:
            AStrategy theStrategy;
      }

        class MyStategy {
        public:
            void DoAlgorithm();
        };
     

        Context<MyStrategy> aContext;

    }
     

  5.     Make Strategy objects optimal
          It is possible to configure Context without a strategy class in which it proceeds
        with default behavior.

Limbo Example


 

All information is taken from the following source:

Erich Gamma, Richard Helm, Ralph Johnson and John Vlissides.  Design Patterns: Elements of
Object-Oriented Software.  Addison Wesley, Reading, 1995.

BACK