Back to list
Views:   10.4K
Replies:  1
Archived

How to identify appropriate Design Patterns to resolve code smells

Hi,

I am involved with an application where there are a lot of coding issues (i.e code smells), such as, many if else conditions, hard coded data passing from one layer to another, etc..

I want to improve the code quality for the application. Can any one please tell me how I can identify that a particular Design Pattern is appropriate to resolve (or refactor) certain pieces of code?

Please let me know if the question is not clear.

Thanks.
Harshad Riswadkar, Sep 14, 2010
Reply 1
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
Nunu Kohli, Sep 14, 2010
Thanks alot Jacob I am already going with Factory pattern but need to know how to implement builder pattern on parallel of factory pattern.
Jul 30, 2010


Stay Inspired!
Join other developers and designers who have already signed up for our mailing list.
Terms     Privacy     Licensing       EULA       Sitemap      
© Data & Object Factory, LLC.
Made with    in Austin, Texas.      Vsn 1.2.2