Question: Consider a travel planning application where there can be multiple ways to travel from one destination to another, e.g. by flight, by boat, by train,
Consider a travel planning application where there can be multiple ways to travel from one destination to another, e.g. by flight, by boat, by train, by bus, etc. This is best achieved using the Strategy Pattern which allows the mode of travel to be changed at run time.

Write the Java code for the three classes Strategy, Context and StrategyPatternDemo. You may assume that all the other classes are fully implemented. In the main() method, create a Context variable for the ByBus mode of travel and do the action.
StrategyPattern Demo Strategy > +main() : void +doAction(): void implements asks Context uses ByBus ByBoat ByFlight -strategy: Strategy +Context(Strategy) +doStrategy(): void +doAction(): void +doAction(): void +doAction(): void
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
