P
Peter
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
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