Strategy

Intent

Define a family of algorithms, encapsulate each one, and make them interchangeable. Strategy lets the algorithm vary independently from clients that use it.

Class diagram of the original GoF pattern

structure-GoF:strategy

Another solution in MixJuice

Solved Problem(s)

Complexity problem
The class structure of the original GoF pattern is complicated. (This problem is not mentioned in the GoF book.)

Used programming technique(s)

Implementation selection for Context.

Consequences

Structure and pseudo code

structure:strategy_sample1

module m {
  define class C {
    define void contextInterface() {
      ... algorithmInterface() ...
    }
    define abstract void algorithmInterface();
  }
}
module m.strategyA extends m {
  class C { void algorithmInterface() {...} }
}
module m.strategyB extends m {
  class C { void algorithmInterface() {...} }
}

Akira TANAKA <akr@m17n.org>, Yuuji ICHISUGI <y-ichisugi@aist.go.jp>

Top