Skip to main content
edited title
Link
Kilian Foth
  • 111k
  • 45
  • 302
  • 323

Does my class violatesviolate the Single Responsibility Principle in SOLID?

Source Link

Does my class violates Single Responsibility Principle in SOLID?

I want to ask:

  1. Whether the Role class violates Single Responsibility Principle in SOLID ? I think deleteAccount() is not belong to Role class but Role class is way to extend code in the future

  2. There are deleteAccount() in Role and Account. That is ok ?

  3. Admin and Moderate violates DRY principle ? Because the deleteAccount() was repeated. If yes, how to fix it ?

  4. How to implement the deleteAccount() which can delete itself account ? Should I use strategy design pattern to do that ?

     class Account: def __init__(self, email, password, security_ans): self.status = "Active" self.role = Member() def deleteAccount(self, dest_email): dest_account = accounts.getByEmail(dest_email) #get account obj from accounts self.role.deleteAccount(self) 

This is my Role class:

class Role: def blockAccount(self, account): raise NotImplementedError("No Permission") class Admin(Role): def deleteAccount(self, account_obj): account_obj.setStatus('Closed') class Moderator(Role): def deleteAccount(self, account_obj): account_obj.setStatus('Closed') class Member(Role): def deleteAccount(self, account_obj): raise NotImplementedError("No Permission")