P
peter
Hi, a "style" question.
There is a method which creates a user in a database. I have to instantiate
a user object, pass it to the method, and I get a completed user object
back.
public IUser Create(IUser user)
{
....
}
where IUser is an interface. Yet in the method itself I find things like:
((User)user).SetId(id);
Where User is a concrete class implementing IUser. Is this horrible? Or is
it perfectly reasonable? (The point of it seems to be to allow the
programmer to set some properties of the user object which the interface
does not declare - there are only getters). Does this mean that if I want to
supply my own implementation of IUser I really have to inherit from User and
not simply implement IUser and pass it to the method?
Thanks,
Peter
There is a method which creates a user in a database. I have to instantiate
a user object, pass it to the method, and I get a completed user object
back.
public IUser Create(IUser user)
{
....
}
where IUser is an interface. Yet in the method itself I find things like:
((User)user).SetId(id);
Where User is a concrete class implementing IUser. Is this horrible? Or is
it perfectly reasonable? (The point of it seems to be to allow the
programmer to set some properties of the user object which the interface
does not declare - there are only getters). Does this mean that if I want to
supply my own implementation of IUser I really have to inherit from User and
not simply implement IUser and pass it to the method?
Thanks,
Peter