Automation Best PracticesMiscellaneous

Refactoring Keyword Driven Approach With Functional Pointers

Although, a developer always tries to write best solution in the code, refactoring is something, which can never be ignored.

A problem may have multiple solutions. However, implementing the best is always on priority. Refactoring is a technique to restructure the code to have best possible solution implemented. Thus, if you are in process of maintaining the code by refactoring the same, one of the best practices is to find a smallest way with minimal maintenance.
Let us discuss one of those solutions here, which may help you to develop such an implementation. Specially, if you have a keyword driven framework with function names as your keywords, you use a lot many select cases.

Let us consider one of the aforesaid examples wherein you have a situation to call a specified function based on a conditional statement (function names are your keywords and user specifies which function to be called in an external datasheet). One of the alternatives to this solution will be to have a select statement implemented, however what if your conditions are increasing gradually or you are adding more functions to your framework and these function are to be called based certain condition (user selection in our case). So, every time you introduce a new function you need to update the select condition. Additionally, for every new condition you will be adding three lines of code
1. Case
2. Function call
3. Break
Now, think about the solution which will not need any updates to be made in the code for every new keyword and all you need to do is to add new function (And that’s it).
The solution is “Functional Pointers”. Let us first understand what functional pointer is?




If you liked this post, say thanks by sharing it.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.