Sunday, June 28, 2009

No If No else Only OOP ;)

While going through the Dzone links , i was happy and amazed to found Anti-IF Campaign . The overall aim of the campaign is to promote OOP usage in place of procedural If's and other conditional programming constructs.This would make you agile and keep complexity under control.

In my current and many of past project , i have seen lots and lots of this happening as this is an easy way for a developer at any level to rationalize behavior using this constructs.But the maintenance hell you get with such crap is huge, even when you are still in System Integration or UAT stage of your project.

To start with applying OOP in your cases ,try to get the abstractions right.This may take some time as this will involve understanding a bit about the domain ,if you already have not.
Another of the best way to get into this mode is refactoring your current code with strong tests under your belt. As i am currently reading Refactoring by Martin Fowler,there is one complete chapter dedicated to removing such rote ,repeating and tangled constructs with delegation and polymorphism .There are other refactorings that talk about putting behaviors in proper classes which again makes this If-else clutter go away and distributes responsibility uniformly across classes.

Hurry!!! Join the Campaign and involve your team.Feel free to share your experiences and thoughts of aligning with Anti-IF Campaign.

Read more...

Sociofluid