Designing a module or feature with classes
Problem Statement
π― Objective
Design a modular, object-oriented system for a given feature, where functionality is decomposed into logical classes with clear responsibilities, relationships, and interactions.
The goal is to demonstrate understanding of OOP principles (Encapsulation, Abstraction, Inheritance, Polymorphism) and good class design practices such as separation of concerns,
extensibility, and maintainability.
πΉ Context
In any large software project, features are implemented as modules β self-contained components that perform a specific function.
Your task is to design a feature/module (for example: authentication, payments, cart management, logging, or notifications) using appropriate classes and interfaces that ensure reusability, testability, and clarity.
β Functional Requirements (Generic Template)
βοΈ Non-Functional Requirements
RequirementDescription
Extensibility
Should allow easy feature addition without modifying existing classes.
Reusability
Designed components can be reused across different modules.
Maintainability
Code should be modular and easy to refactor.
Testability
Classes should be unit-testable with clear interfaces.
Performance
Should minimize unnecessary dependencies or computations.
π§© Example: Design a Logging Module
To illustrate how to βdesign a module or feature with classes,β letβs take a Logging System as an example.
π§ Problem Context
You need to design a Logging Module that allows different parts of an application to log messages (INFO, ERROR, DEBUG, etc.) to various destinations β e.g., console, file, or remote server.
β Functional Requirements
π§± Core Classes
Class and Responsibility
Logger
Central class to log messages; delegates to handlers.
LogHandler (interface)
Abstract handler for sending logs to a destination.
ConsoleHandler
Writes logs to console.
FileHandler
Writes logs to a file.
RemoteHandler
Sends logs to a remote API endpoint.
LogFormatter
Formats log messages (e.g., timestamps, thread info).
LogLevel (enum)
Defines levels (INFO, WARN, ERROR, DEBUG).
π§Ύ Example Class Diagram (Text Representation)
1
2ββββββββββββββββββββββββββββ
3β Logger β
4ββββββββββββββββββββββββββββ
5β - handlers: List<LogHandler> β
6ββββββββββββββββββββββββββββ
7β + log(level, message) β
8β + addHandler(handler) β
9ββββββββββββ¬ββββββββββββββββ
10 β
11 βΌ
12ββββββββββββββββββββββββββββ
13β LogHandler (IF) β
14ββββββββββββββββββββββββββββ
15β + handle(level, message) β
16ββββββββββββ¬ββββββββββββββββ
17 βββββββββΌβββββββββββββ
18 βΌ βΌ βΌ
19ConsoleHandler FileHandler RemoteHandler
20
21ββββββββββββββββββββββββββββ
22β LogFormatter β
23ββββββββββββββββββββββββββββ
24β + format(level, message) β
25ββββββββββββββββββββββββββββπ‘ Example Flow
π§ Design Patterns Used
Pattern and Use
Strategy Pattern
Different log handlers implement same interface.
Factory Pattern
For creating handlers based on configuration.
Singleton
Single global Logger instance (optional).
Decorator
Add extra functionality (e.g., timestamp, context).
π¬ Example Interview Prompt Summary
Design a module or feature using classes.
For example, design a Logging module that can log messages at different levels to multiple destinations.
Show your class structure, relationships, and how youβd ensure extensibility and clean separation of concerns.
π Other Example Features You Could Design
Feature and Description
Authentication Module
Classes for User, AuthService, TokenManager, PasswordEncoder.
Payment Gateway
Classes for Payment, PaymentProcessor, CreditCard, PayPal, UPI.
Email Notification System
Classes for Email, SMTPClient, TemplateEngine, NotificationService.
Cache System
Classes for Cache, LRUCache, CacheManager.
Shopping Cart Module
Classes for Cart, CartItem, Product, CartService.
π§© Template for Any βFeature with Classesβ Problem
Design a [Feature/Module Name].