Refactoring

Posted by Rajansvdotnet under ASP.NET on 9/15/2008 | Views : 1798 | Status : [Member] | Replies : 1
Hi,

I want to know the details related code refactoring in Net 2.0.

i know only one thing that is, code refactoring means dividing code.

Regards
Raja




Responses

Posted by: Raja on: 9/15/2008 [Member] Starter

Up
0
Down
Code refactoring is not specific to .NET 2.0 but in VS 2005 onwards there is a Refactor menu short cut menu, its a way of writing code.

Lets understand this by example.
You have a Page_Load method and you have to populate 4 GridView into it. In this case instead of writing all code into Page_Load method, divide the functionality of populating every GridView into 4 different method and call those methods into Page_Load.

Code without Refactoring

protected void Page_Load(object sender, EventArgs e)

{
// Donot write all code to populate GridView1
// Donot write all code to populate GridView2
// Donot write all code to populate GridView3
// Donot write all code to populate GridView4
}


instead write method for them and call inside Page_Load

Code after Refactoring
protected void Page_Load(object sender, EventArgs e)

{
PopulateGridView1();
PopulateGridView2();
PopulateGridView3();
PopulateGridView4();
}

private void PopulateGridView1()
{
// write your code to populate GridView1
}

private void PopulateGridView2()
{
// write your code to populate GridView2
}

private void PopulateGridView3()
{
// write your code to populate GridView3
}

private void PopulateGridView4()
{
// write your code to populate GridView4
}


Hope this will help you understand Refactoring.

Thanks

Regards,
Raja, USA

Rajansvdotnet, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response