Design Pattern: Strategy

The Strategy design pattern is a behavioral pattern, where it defines a family of functionality, encapsulating each of them and making them interchangeable.

This strategy pattern can be useful in a road navigator software, where you have an interface called routeStrategy and it has an abstract buildRoute() function. An all the possible route strategies like RoadStrategy, PubTransportStrategy and WalkingStrategy classes will implement route strategy and override the buildRoute().

This will allow the navigator object to choose between strategies during runtime by calling the buildRoute().

Leave a comment

Design a site like this with WordPress.com
Get started