Wednesday, July 28, 2010

Coding without ifs and switch cases!!

I was recently posed with some programming problems, revolving largely around applying OO skills in designing the solutions. The focus was essentially on design; the solution itself once designed could be easily coded in a matter of hours. However, the more interesting part of the exercise itself was the condition that in entire design there shouldn’t be any if ... else ... and switch cases. If absolutely unavoidable, one could use if but not more than twice!

This absolutely intrigued me, because all the OO languages provide these constructs and wasn’t programming/problem solving based upon conditional checks and doing different things in different scenarios. Well nevertheless I did my part of research seeking reasons as to why and how branching could and should be avoided while in OO paradigm.

Polymorphism and Dependency Injection came up as two major concepts that are better taught and poorly used most of the times. The effort that I put in on doing this exercise has definitely given me lot of insight into better designing and modeling of Value Objects, Classes and Interfaces.

I would recommend every programmer to delve into such semantic based aesthetics of any paradigm we use to conceptualize/simulate our problem and solution space. Please leave a comment about any more similar programming paradoxes /best practices/experiences. I will continue to explore these further. To better designs...

No comments:

Post a Comment