Resharper can provide this functionality, e.g.,
- You can write your Person class first.
- You can extract your interface by pulling members up to the IPerson interface.
Consequently you can have Visual Studio auto-generate implementation stubs for you.
UPDATE
Anyway, let's expound on interfaces first, citing the code you provided in your question:
public class interface Person : IPerson
{
int ID { get; protected set; }
string FirstName { get; set; }
string LastName { get; set; }
string FullName { get { return FirstName + " " + LastName; } }
}
You have to understand that an Interface is not an Abstract Class. An interface is merely a contract, a blueprint of sorts, which means that it will tell an object what to expect in another object without really caring about how it is implemented.
An Abstract Class, on the other hand, can contain snippets of functionality that can be inherited and overridden.
In the case above, your "interface" is invalid because:
- you couldn't declare scope constraints on interfaces (public, private, protected, internal) as that is an implementation detail
- you couldn't declare a default implementation (e.g., your
FullName
property) because again, that is an implementation detail
It appears to me what you really really want is an abstract class, e.g.,
public abstract class BasePerson
{
public abstract int ID { get; protected set; }
public string FirstName { get; set; }
public string LastName { get; set; }
public virtual string FullName { get { return FirstName + " " + LastName; } }
}
I'm just guessing, but maybe that's what you really need.
UPDATE 2
Okay, I think I'm getting at what you want to happen, so what you want is to be able to write this:
public interface IPerson
{
int ID { get; set; }
string FirstName { get; set; }
string LastName { get; set; }
string FullName { get; }
}
And then for your implementation only need to write this:
public class Person : IPerson
{
public int ID { get; protected set; }
public string FullName { get { return FirstName + " " + LastName; } }
}
Without needing to specify the FirstName and LastName properties.
First problem that we need to tackle is the fact that interfaces don't allow access delimiters in its implementation: what would happen is that the properties would inherit the default access delimiter, which is private.
Second is the fact that while in our eyes string FirstName { get; set; }
in an interface and public string FirstName { get; set; }
in a class are the same, they are actually not:
- in an interface, the property definition will indicate that the method signatures for the getter and/or setter methods will be available for all classes implementing that interface.
- in a class, the property definition will instruct the CLR to create an anonymous object which will hold the value of the said Property.
Subtle difference for the programmer, worlds apart for the compiler.
Lastly, when you do specify that you are implementing an interface, Visual Studio does perform synctactic magic that automatically makes those property stubs for you.