Search code examples
design-patternsdaosingle-responsibility-principlecohesion

Does the DAO pattern spoils cohesion /SRP?


Let's use as example:

class AccountDAO {
    create(){..}
    read(){..}
    update(){..}
    delete() {..}
}

How many responsibilities are there? 1 or 4?


Solution

  • 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.