DAO 模式是否会破坏凝聚力/SRP?
让我们举个例子:
class AccountDAO {
create(){..}
read(){..}
update(){..}
delete() {..}
}
有多少责任? 1 还是 4?
Let's use as example:
class AccountDAO {
create(){..}
read(){..}
update(){..}
delete() {..}
}
How many responsibilities are there? 1 or 4?
SRP不应该被严格地理解。一个对象应该有很少的职责,而不是“一个”。
这里AccountDAO只负责Account持久化,因此它只有一项职责。
SRP shouldn't be understood in a strict manner. One object should have very few responsibilities, not "one".
Here AccountDAO is only responsible for Account persistence, so it has only one responsibility.