Gunnar Peipman's ASP.NET blog

ASP.NET, C#, SharePoint, SQL Server and general software development topics.

Sponsors

News

 
 
 
DZone MVB

Links

Social

Refactoring: parameterize constructor

In legacy code you may find classes with constructor where some objects are created and initialized. These classes are not easily testable because they depend on other classes and therefore when you unit test these classes they may also throw exceptions of classes they depend on. In these cases we can use parameterize constructor refactoring.

 

NB! This blog is moved to gunnarpeipman.com

Click here to go to article

Comments

Brian Canzanella said:

I like doing things like this with constructor chaining...

(Mailer implements IMailer)

public class MassMailer

{

   private IMailer mailer;

   public MassMailer():this(new Mailer()){}

   public MassMailer(IMailer mailer)

   {

       this.mailer = mailer;

   }

}

# June 8, 2009 2:50 PM

Abhijit said:

Congratulations...you've discovered Constructors!

# June 9, 2009 1:00 AM