Future Proof Design with Strategy Factories

Raghavan Lakshmana
craftsmanship
Published in
3 min readOct 1, 2019

--

I came across a problem at work which demanded a future proof design so that any new business rule can be plugged-in on a case-by-case basis. Let me explain the problem with something everyone can relate to. Google maps takes in a start and target destination with a direction option like driving, walking, public transit, etc.. and some backend engine will find the appropriate route based on the input. Several years ago when Google launched maps, they had only two direction options like walking and driving. Now, it supports several options like flying, public-transit, carpool. In the future, it may support even more options like self-driving, self-flying. I had to design a backend system where such new functionalities would be added but in a much more faster frequency. I decided to use the Strategy Factory pattern to design such a system.

Google maps with walking directions

A healthy relationship between product and engineering happens when the engineering systems are robust enough to support the present and flexible enough to extend for the future. Design patterns play a vital role in ensuring such extensibility. Strategy factory allows to plug-in the business rules whenever needed with minimal code change.

--

--