Skip to content
Low Level Design Mastery Logo
LowLevelDesign Mastery

Assign Responsibilities

Master responsibility assignment - the key to clean, maintainable code design!

Assigning responsibilities correctly is crucial for creating maintainable, testable, and scalable code. Poor responsibility assignment leads to god classes, tight coupling, and code that’s hard to understand and modify.

Diagram

A responsibility is a reason for a class to change. Each class should have one primary responsibility - one reason to exist and one reason to change.

  1. Data Management - Storing and managing data
  2. Business Logic - Implementing business rules
  3. Coordination - Coordinating between other classes
  4. Validation - Validating inputs and states
  5. Communication - Interacting with external systems
Diagram

Definition: A class should have only one reason to change.

What this means:

  • Each class should do one thing and do it well
  • If a class has multiple reasons to change, split it
  • Changes to one responsibility shouldn’t affect others
Diagram
  1. Identify what each entity needs to do
  2. Group related operations
  3. Assign to appropriate class
  4. Ensure single responsibility
  5. Check for cohesion

Entities Identified:

  • Book
  • Member
  • Loan
  • Reservation
  • Fine

Let’s assign responsibilities:

What does a Book need to do?

  • Store book information (title, author, ISBN)
  • Track availability status
  • Know its location in library

Book Responsibilities:

Responsibility: Manage book data and availability state

What does a Loan need to do?

  • Store loan information (book, member, dates)
  • Calculate due date
  • Check if overdue
  • Calculate fine amount

Loan Responsibilities:

Responsibility: Manage loan lifecycle and calculate fines

Diagram

Responsibility: Store and manage data

Example:

When to use: When you need to store data with minimal logic

Responsibility: Implement business rules and calculations

Example:

When to use: When you have complex business rules

Responsibility: Coordinate between multiple classes

Example:

When to use: When you need to coordinate multiple operations

Responsibility: Validate inputs and states

Example:

When to use: When you need to validate before operations

Responsibility: Handle data persistence

Example:

When to use: When you need to abstract data access


Part 4: Common Mistakes and How to Avoid Them

Section titled “Part 4: Common Mistakes and How to Avoid Them”

Mistake 1: God Class (Too Many Responsibilities)

Section titled “Mistake 1: God Class (Too Many Responsibilities)”

Bad Example:

Problems:

  • Too many reasons to change
  • Hard to test
  • Hard to maintain
  • Violates SRP

Good Example:

Diagram

Mistake 2: Anemic Domain Model (Too Few Responsibilities)

Section titled “Mistake 2: Anemic Domain Model (Too Few Responsibilities)”

Bad Example:

Problems:

  • Data and behavior separated
  • Objects are just data containers
  • Logic scattered across managers

Good Example:

Bad Example:

Problem: Book is responsible for sending notifications (should be NotificationService)

Good Example:


Part 5: Responsibility Assignment Framework

Section titled “Part 5: Responsibility Assignment Framework”
Diagram

For each responsibility, ask:

  1. Who owns this data? → Assign to that class
  2. What is the primary purpose? → Assign to class with that purpose
  3. Does it need coordination? → Create a coordinator/service
  4. Is it reusable? → Create a separate utility/service
  5. Does it violate SRP? → Split into multiple classes

Entities:

  • ParkingLot
  • ParkingSpot
  • Vehicle
  • Ticket
  • Payment

Responsibility Assignment:

What should ParkingLot do?

  • Manage collection of parking spots
  • Find available spots
  • Assign spots to vehicles
  • Release spots when vehicles leave

ParkingLot Class:

Responsibility: Coordinate parking operations

What should ParkingSpot do?

  • Track its own state (occupied/available)
  • Know its type and location
  • Park/unpark vehicles

ParkingSpot Class:

Responsibility: Manage spot state and vehicle assignment

What should Ticket do?

  • Store entry information
  • Calculate parking duration
  • Reference vehicle and spot

Ticket Class:

Responsibility: Track parking session and calculate duration

Visual: Complete Responsibility Assignment

Section titled “Visual: Complete Responsibility Assignment”
Diagram

Cohesion measures how related the responsibilities within a class are.

Types:

  • High Cohesion - All methods work together for one purpose
  • Low Cohesion - Methods are unrelated
Diagram

Coupling measures how dependent classes are on each other.

Types:

  • Low Coupling - Classes are independent
  • High Coupling - Classes are tightly dependent
Diagram

Aim for:


  • Single Responsibility Principle - One reason to change
  • Identify what each class needs to do - Group related operations
  • Avoid God Classes - Split large classes
  • Avoid Anemic Models - Include behavior with data
  • High Cohesion - Related responsibilities together
  • Low Coupling - Independent classes
  • Use patterns - Data Holder, Business Logic, Coordinator, Validator, Repository

When assigning responsibilities, ensure:

  • Each class has one primary responsibility
  • Responsibilities are related (high cohesion)
  • Classes are independent (low coupling)
  • No God Classes - Split if too many responsibilities
  • No Anemic Models - Include behavior with data
  • Clear purpose - Easy to understand what class does
Diagram

Now that you’ve mastered assigning responsibilities, let’s learn how to create class diagrams:

Next: Class Diagrams →

This next guide will teach you how to visualize your design with class diagrams, showing relationships, inheritance, and composition!


💡 Time to Practice!

Now that you understand the concepts, put them into practice with our interactive playground. Build UML diagrams, write code, and get AI-powered feedback.

Browse All Problems