我假设由于查询语言位于控制器内(通常)它属于该组件,但如果我扮演魔鬼的拥护者,我认为查询语言是在模型的域内执行的,并且与该组件紧密耦合,因此它也可能是其中的一部分。
有人知道答案吗?有直接答案还是技术特定?
答案 0 :(得分:2)
两者都是实现它的合法方式。问题是您需要向用户公开应用程序的内容和方式。在Patterns Of Enterprise Application Architecture(再次说明,我真的想引用那本书;)他们提供了两种方法来实现Domain Model:
作为代码示例:
// This can also be your controller
class UserService
{
void save(User user)
{
user.password = md5(user.password)
// Do the save query like "INSER INTO users"... or some ORM stuff
}
}
class User
{
String username;
String password;
// The following methods might be added if you put your application logic in the domain model
void setPassword(String password)
{
// Creates a dependency to the hashing algorithm used
this.password = md5(password)
}
void save()
{
// This generates a dependency to your backend even though
// the user object doesn't need to know to which backend it gets saved
// INSET INTO users
}
}