Class Context

java.lang.Object
Behavioral.Strategy.Context

public class Context extends Object
The Context class maintains a reference to a Strategy object and delegates the execution to it.
  • Constructor Details

    • Context

      public Context()
      Default constructor for Context.
  • Method Details

    • setStrategy

      public void setStrategy(Strategy strategy)
      Set the current strategy.
      Parameters:
      strategy - The strategy to use.
    • executeStrategy

      public String executeStrategy()
      Execute the current strategy's algorithm.
      Returns:
      The result of the algorithm as a string.
      Throws:
      IllegalStateException - if no strategy is set.