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)
}
}
>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.