Package Behavioral.Strategy
Class Context
java.lang.Object
Behavioral.Strategy.Context
The Context class maintains a reference to a Strategy object and delegates the execution to it.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionExecute the current strategy's algorithm.voidsetStrategy(Strategy strategy) Set the current strategy.
-
Constructor Details
-
Context
public Context()Default constructor for Context.
-
-
Method Details
-
setStrategy
Set the current strategy.- Parameters:
strategy- The strategy to use.
-
executeStrategy
Execute the current strategy's algorithm.- Returns:
- The result of the algorithm as a string.
- Throws:
IllegalStateException- if no strategy is set.
-