对不起,但我想不出超出你的榜样。用户对象不应该有登录方法。我做的是有以下几种
public class User
{
public bool ConfirmPassword(string password)
{
...
}
}
然后一个存储库。这通过他们的userName找到用户,然后检查ConfirmPassword以查看它是否正确,如果不正确则返回null。
public interface IUserRepository
{
..other stuff..
User GetByUserNameAndPassword(string userName, string password);
}
至于验证,我通常有2种获取约束的方法。
//The constraint itself
public interface IConstraint
{
string Name { get; }
bool IsValid();
}
//A way to get constraints that are inexpensive to evaluate, such
//as Name != null etc. This can be implemented as a service to provide
//custom constraints from an external source (such as rows in a DB)
//which then additionally checks "instance" if it implements the
//interface and adds its constraints to the result too.
//These are the kinds of constraints I evaluated in the GUI every
//time the object changes, so I can show a list of errors.
public interface IConstraintProvider
{
IEnumerable<IConstraint> GetConstraints(object instance);
}
//Finally a way to get constraints that are expensive to evaluate, this
//includes checking invariants that might involve DB access. These constraints
//(along with the cheap evaluation constraints) are all evaluated before
//my persistence service attempts to write the object's changes to the DB
public interface IPreSaveConstraintProvider
{
IEnumerable<IConstraint> GetConstraints(object instance);
}
这是一个有趣的方式来看看它。基本上,它会告诉我在哪里需要将我的物理模型的某些部分转换为更多逻辑模型。这将使验证零件更容易。我会看看这是怎么回事。谢谢! – Jonathan 2009-02-06 22:37:51
是的。要做的事情是考虑DOMAIN模型。在这里你可以在你的“故事”中看到你的会话可以匿名的情况;对象模型应该表示这一点。另一个版本会有一个会话 - 一个可以匿名的用户。 – 2009-02-06 22:48:17