Focus on Microsoft Technologies - Tutorials, Articles, Code Samples.

Tuesday, September 12, 2006

Refactoring – Encapsulate Field in Visual Studio.NET

Refactoring is a disciplined technique of restructuring your existing body of code by altering its internal structure without changing its external behavior.

Encapsulating a field means that instead of directly accessing a field, you will use methods to read from and write to the field. Usually the methods you create to access the field have public visibility, while the field being encapsulated is given private visibility. This allows the developer to restrict what actions can be performed by another user of the code.

Visual Studio 2005 automates this process with the Encapsulate Field refactoring. When you select the Encapsulate Field option, you are prompted to configure the scope of the modification. When you are satisfied, you can preview the change and its impact on your code before accepting it.

The Encapsulate Field refactoring in Visual Studio Team System.

Post a Comment