Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

On Clean Architecture, Should Entity represent plural and singular?

Wondering about this because for instance, if I have Entity User and Users, If im understanding correctly about Single responsibility principle I should seperate them? my methods may sepearate policies for db interface of methods that affect a single user or multiple user…

i.e. rough example:

interface UserDb {
  createUser()
  getUserById()
  deleteSingleUser()
}

interface UsersDb {
  deleteMultipleUsers()
  flagMultipleUser()
}

interface UserObj {
  id: string
  reportedFlag: boolean
  createdOn: string
  hashedPassword: string
  name: string
}

class User {

  #dbAccessor: UserDb;
  constructor(dbAccessor) {
  #dbAccessor = dbAccessor;
}

  createNewUser(email, hashedpw) {
    this.#dbAccessor.createUser(email, hashedpw)
  }

 // ...
}

class Users {

  #dbAccessor: UsersDb;
  constructor(dbAccessor) {
  #dbAccessor = dbAccessor;
}

  flagUsers(userIdArr) {
  this.#dbAccessor.flagMultipleUsers(userIdArr)
  }
}

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

You can, but most places don’t. Single responsibility is mostly just seen for the type of Entity. For example I have a class OrderService which has the methods: place(order: Order) and place(orders : List[Order]).

It’s more about not mixing for example logic of the Costumer and the Order so that when anything changes anywhere it changes in only ONE place and doesn’t directly (mostly) affect other logic.

Seperating single and plural implementations will only add an extra place to check for logic.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading