50
50
Sep 14, 2010
HI,
There are multiple ways in which u can handle the situation.
1. Refactor your code:
Review code and see where there is repetetive code. Create small methods and pass paramaters for small differences in repetive code.
2. Once you are finished and convinced that the code is refactored into private methods, u wud find that there needs to be refactoring across multiple classes. E.g similar code in multiple classes with small differences relvant to that specific class.
For this, create a separate class and move methods there. You would realize that either your classes containing common code need to inherit from this new class or need to have a refernce for it. Well, doing this is using design patterns.
3.Now in case if else statments consit of creating mutiple objects:
if(Case I)
A a = new A();
else
B b = new B();
such a case calls for creating common class and inherting A and B from same. use factory to create object at runtime.
There are just few small samples, this may help you.
Regards,
Pankaj