Bird
Raised Fist0
LLDsystem_design~7 mins

Identifying classes from requirements in LLD - System Design Guide

Choose your learning style10 modes available
Problem Statement
When developers start coding without clearly identifying the main classes, the design becomes messy and hard to maintain. This leads to duplicated code, unclear responsibilities, and difficulty in extending the system later.
Solution
By carefully analyzing the requirements, we find the main nouns and verbs that represent objects and actions. We then create classes for these objects with clear responsibilities, which helps organize the code logically and makes it easier to maintain and extend.
Architecture
Requirements
→Identify Nouns
↓
Define Classes with
Define Classes with

This diagram shows the flow from requirements to identifying nouns and then defining classes with clear responsibilities.

Trade-offs
✓ Pros
→
Improves code organization by mapping real-world concepts to classes.
→
Makes the system easier to understand and maintain.
→
Helps identify clear responsibilities for each class, reducing duplicated code.
✗ Cons
→
Requires careful reading and interpretation of requirements, which can be time-consuming.
→
May lead to too many small classes if over-applied, increasing complexity.
→
Initial design might miss some classes if requirements are incomplete or ambiguous.
Use this approach when starting a new system or feature with clear textual requirements and when maintainability and clarity are priorities.
Avoid relying solely on this when requirements are vague, rapidly changing, or when prototyping quickly without focus on design.
Real World Examples
Amazon
Amazon identifies classes like Order, Customer, and Product from requirements to organize their e-commerce system logically.
Uber
Uber models classes such as Driver, Rider, and Trip from their ride-sharing requirements to separate concerns clearly.
LinkedIn
LinkedIn uses class identification from requirements to define entities like User, Connection, and Message for their social network.
Code Example
The before code mixes customer and order logic in one function, making it hard to maintain. After identifying classes Customer and Order from requirements, responsibilities are separated, improving clarity and extensibility.
LLD
### Before: No clear classes, everything in one function

def process_order(order_data):
    print(f"Processing order for {order_data['customer_name']}")
    # code mixes customer and order logic


### After: Classes identified from requirements

class Customer:
    def __init__(self, name):
        self.name = name

class Order:
    def __init__(self, customer):
        self.customer = customer

    def process(self):
        print(f"Processing order for {self.customer.name}")

# Usage
customer = Customer("Alice")
order = Order(customer)
order.process()
OutputSuccess
Alternatives
Entity-Relationship Modeling
Focuses on data entities and their relationships rather than behavior and responsibilities.
Use when: Choose when the system is data-centric and database design is the priority.
Use Case Driven Design
Starts from user interactions and scenarios rather than nouns in requirements.
Use when: Choose when user workflows and interactions are the main focus.
Summary
Identifying classes from requirements prevents messy, unorganized code by mapping real-world concepts to code.
It involves finding key nouns and defining classes with clear responsibilities to improve maintainability.
This approach is best when requirements are clear and stable, helping build a solid foundation for the system.

Practice

(1/5)
1. Which of the following is most likely a class when designing a library management system?
easy
A. Return
B. Borrow
C. Book
D. Search

Solution

  1. Step 1: Identify nouns in the requirement

    Classes usually come from nouns. Here, 'Book' is a noun representing an object.
  2. Step 2: Differentiate between nouns and verbs

    'Borrow', 'Return', and 'Search' are actions (verbs), so they are methods, not classes.
  3. Final Answer:

    Book -> Option C
  4. Quick Check:

    Class = Noun = Book [OK]
Hint: Pick the noun as class, verbs become methods [OK]
Common Mistakes:
  • Choosing verbs as classes
  • Confusing actions with objects
  • Ignoring nouns in requirements
2. In a ride-sharing app, which of these is the correct way to represent a class in code?
easy
A. class Driver {}
B. function Driver() {}
C. var Driver = 5;
D. let driver = 'John';

Solution

  1. Step 1: Understand class syntax in LLD context

    Classes are defined with the keyword 'class' followed by the class name.
  2. Step 2: Check options for class declaration

    class Driver {} uses 'class Driver {}' which is correct syntax for a class.
  3. Final Answer:

    class Driver {} -> Option A
  4. Quick Check:

    Class syntax uses 'class' keyword [OK]
Hint: Look for 'class' keyword to identify class declaration [OK]
Common Mistakes:
  • Using function instead of class
  • Assigning class name to variable
  • Confusing variables with classes
3. Given the requirement: "A hotel booking system must manage Guests, Rooms, and Bookings." Which of these is the correct set of classes identified?
medium
A. [Booking, Book, GuestList]
B. [Guest, Room, Booking]
C. [Guest, Book, RoomBooking]
D. [Room, Guest, ReservationList]

Solution

  1. Step 1: Extract nouns from the requirement

    The nouns are Guests, Rooms, and Bookings, which represent objects.
  2. Step 2: Match nouns to class names

    Classes should be singular nouns representing entities: Guest, Room, Booking.
  3. Final Answer:

    [Guest, Room, Booking] -> Option B
  4. Quick Check:

    Classes = Nouns = Guest, Room, Booking [OK]
Hint: Pick singular nouns as class names from requirements [OK]
Common Mistakes:
  • Using verbs as classes
  • Using plural or combined names incorrectly
  • Adding unrelated terms
4. You have a requirement: "The system should allow Users to login and logout." Which of the following is an error in identifying classes and methods?
medium
A. Class: User; Methods: login(), logout()
B. Class: UserAccount; Methods: login(), logout()
C. Class: User; Methods: authenticate(), logout()
D. Class: Login; Methods: user(), logout()

Solution

  1. Step 1: Identify nouns and verbs

    'User' is a noun (class), 'login' and 'logout' are actions (methods).
  2. Step 2: Check option correctness

    Class: Login; Methods: user(), logout() incorrectly uses 'Login' as a class and 'user()' as a method, which reverses noun and verb roles.
  3. Final Answer:

    Class: Login; Methods: user(), logout() -> Option D
  4. Quick Check:

    Class = noun, Method = verb [OK]
Hint: Classes are nouns; methods are verbs [OK]
Common Mistakes:
  • Using verbs as classes
  • Naming methods as nouns
  • Mixing class and method roles
5. A food delivery app requirement states: "Customers place Orders, Restaurants prepare Meals, and DeliveryAgents deliver Orders." Which classes should be created to model this system correctly?
hard
A. [Customer, Order, Restaurant, Meal, DeliveryAgent]
B. [Customer, PlaceOrder, Restaurant, Meal, Deliver]
C. [CustomerOrder, RestaurantMeal, Delivery]
D. [Order, Meal, DeliveryAgent, Place]

Solution

  1. Step 1: Identify all nouns in the requirement

    Nouns are Customers, Orders, Restaurants, Meals, DeliveryAgents.
  2. Step 2: Use nouns as class names and verbs as methods

    Classes should be Customer, Order, Restaurant, Meal, DeliveryAgent. Actions like 'place' and 'deliver' become methods.
  3. Final Answer:

    [Customer, Order, Restaurant, Meal, DeliveryAgent] -> Option A
  4. Quick Check:

    Classes = Nouns only, verbs become methods [OK]
Hint: Classes = nouns; actions = methods in those classes [OK]
Common Mistakes:
  • Using verbs as classes
  • Combining nouns incorrectly
  • Omitting important entities
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard