SRP

Definition

SRP, or the Single Responsibility Principle, is a software design principle that states a class or module should have one, and only one, reason to change. This principle is part of the SOLID principles of object-oriented design and aims to enhance code maintainability and reduce complexity by ensuring that each class or module addresses a single concern or functionality.

Secure Settings Example

# Python example adhering to SRP
class UserAuthenticator:
    def authenticate(self, username, password):
        # Logic for authenticating a user
        pass

class UserDataManager:
    def save_user_data(self, user_data):
        # Logic for saving user data
        pass

# Each class has a single responsibility

Insecure Settings Example

# Python example violating SRP
class UserManager:
    def authenticate(self, username, password):
        # Logic for authenticating a user
        pass

    def save_user_data(self, user_data):
        # Logic for saving user data
        pass

# The UserManager class has multiple responsibilities