Even when it seems like overkill, I would consider it more of a discipline.
You have to get used to referring to things by their interface name "on the
outside world" rather than their concrete implementation.
Writing and using a bunch of concrete classes all the time is not OO
programming.
User u = new User();
vs
IUser u = new User();
OR
IUser u = UserFactory.Cre ateNewUser();
Your controller classes definately need interfaces..... .
IUserController
IUser GetSingleUser(i nt customerId)
IUserCollection GetAllUsers()
void UpdateSingleUse r(IUser u)
You would see this very clearly with how WCF forces a contract....
But I 'hear ya', especially when you know you're only going to have 1
concrete for pretty much "all time", it seems like overkill a tad....
but go ahead and discipline yourself, and the one day that it really pays
off in a big way, you'll be like "Man, I'm glad I took that extra 4 minutes
back then".
One off shoot advantage is that you'll always be able to see a very clean
contract when you look at the interface definition.
Aka, when you pull up the code for IUser, it'll just be the contract, and
its much easier to look at then a concrete with lots and lots and lots of
lines of code.
I'm sure you'll get some other comments. Those are just a few from my side.
.............
Here's a small (downloadable) example of interfaces and WCF btw:
http://sholliday.space s.live.com/Blog/cns!A68482B9628 A842A!158.entry
"Peter" <xd****@hotmail .comwrote in message
news:ek******** ******@TK2MSFTN GP02.phx.gbl...
Hi
I was wondering about the use of interfaces for "data classes".
Actually I don't know the accepted term for these types of classes -
they are simply classes which have getters and setters, to contain data
and not really provide any functions.
Is it worth defining interfaces for these types of classes, or is it
"overkill"?
Eg. I might have a class like:
public class User : IUser
{
public string Name { get; set; }
public string Address { get; set; }
public DateTime Birthdate { get; set; }
}
public interface IUser
{
string Name { get; }
string Address { get; }
DateTime Birthdate { get; }
}
In this case, the interface only defines the getters, but setters might
also be defined.
And some other class creates the user objects in a method:
public IUser GetUser()
{
User user = new User();
// set properties
return user;
}
Thanks,
Peter