In this blog you will learn how to encapsulate field
and extract interface using Refactor.
First of all add a new class and declare a variable
email:
public class UserLog
{
private string email;
public
UserLog()
{
//
//
TODO: Add constructor logic here
//
}
}
Now
right click on email and select refactor and select Encapsulate Field.
Image
1.
![img2.jpg]()
Image
2.
And click
OK.
Image
3.
See you
class code now:
Private string email;
Public string Email
{
get { return email; }
set {
email = value; }
}
Now extract
interface, right click on class name and click on Refactor and select Extract
Interface.
Image
4.
Now
provide interface name and select public menbers.
![img5.jpg]()
Image
5.
Click OK.
As you
can see a new interface has been added in App_Code folder.
using System;
interface IUserLog
{
string
Email { get; set;
}
}
As you
can see your class is inheriting by this interface.
public class UserLog : IUserLog
{
private string email;
public string Email
{
get { return email; }
set {
email = value; }
}
public
UserLog()
{
//
//
TODO: Add constructor logic here
//
}
}