In one of my previous projects we had to perform series of complex validations to prepare some input data. Below will explain the scenario.
- Call a service and perform some complex validations based on this service response to prepare one of the input values for using it in another service call.
- You may need to check for multiple inputs with separate complex logic, but at the end you would select only a particular input for another service call.
- You decide the number of inputs. The validation will be performed for all these inputs. You may add or remove number of inputs at any point of time so, we need a flexible way to specify that.
Generally, we use multiple if...else blocks, but, it would lead to readability, maintainability issues. Hence, we came up with an approach of using strategy pattern via Enum.
The approach is explained with working sample code and posted in DZone site. Hope this will be useful.
Post a Comment