
66
|
Chapter 2, Master the Editor
#14 Refactor Your Code
HACK
return _isStarted;
}
set
{
_isStarted = value;
}
}
This function comes in handy even when you are not refactoring. When cre-
ating a class for the first time, you can create the private fields and then use
this function to create all of the necessary public properties.
Extract Interface
The Extract Interface function looks at your current class and creates an
interface based on its public methods and properties. For example, suppose
you want to create an interface for objects that can be “started”; this inter-
face would include a Boolean property, in this case
IsStarted, which, when
set, has the side effect of “starting” the object (some kind of vehicle or item
with an on/off switch). First, right-click on the class name and click the
Extract Interface menu item; this displays the Extract Interface dialog, which
is shown in Figure 2-36.
The default interface name is
IVehicle; change it to IStart and then select
the
IsStarted property. After you click OK, Visual Studio creates a new file
called IStart.cs with the following piece of code:
Figure 2-36. Extract Interface dialog