𝗟𝗟𝗗 𝗗𝗲𝘀𝗶𝗴𝗻 𝗣𝗿𝗼𝗰𝗲𝘀𝘀 (𝗙𝗿𝗼𝗺 𝗥𝗲𝗾𝘂𝗶𝗿𝗲𝗺𝗲𝗻𝘁𝘀 𝘁𝗼 𝗖𝗼𝗱𝗲)
Low Level Design is not about writing code immediately. It is about following a structured process.
Follow these steps to move from a problem statement to working code.
- Understand the Requirements Do not jump to classes. First, find out what the system must do.
- What features does it need?
- What actions must it support?
- What changes might happen later?
- Identify Nouns to Find Classes Look for nouns in your requirements. Nouns become your classes. Example: A Document Editor
- Nouns: Document, Text, Image, Storage, Editor.
- Classes: Document, TextElement, ImageElement, Storage, DocumentEditor.
Example: A Parking Lot
- Nouns: ParkingLot, Floor, Slot, Vehicle, Ticket.
- Classes: ParkingLot, Floor, Slot, Vehicle, Ticket.
- Use IS-A for Inheritance Ask yourself: "Is the child a type of the parent?"
- TextElement IS-A DocumentElement.
- Car IS-A Vehicle.
- Dog IS-A Animal. If the answer is yes, use inheritance.
- Use HAS-A for Composition Ask yourself: "Does one object contain another?"
- A Document HAS-A collection of elements.
- A ParkingLot HAS-A set of floors.
- A Car HAS-A engine. Use composition to link these objects.
- Identify Verbs to Find Methods Look for actions in the requirements. Verbs become your methods.
- Add text becomes addText().
- Save document becomes save().
- Park vehicle becomes parkVehicle().
- Plan for Change with Interfaces Think about future updates. If you save a document, you might use a File, a Database, or the Cloud.
- Create an interface called Persistence.
- Create implementations like FileStorage or DBStorage. This allows you to add CloudStorage later without changing your existing code.
- Draw UML and Write Code Once you have classes, inheritance, composition, and methods, draw a UML diagram. This acts as your blueprint. Finally, convert that blueprint into clean code.
Summary Flow:
- Requirements
- Nouns to Classes
- IS-A to Inheritance
- HAS-A to Composition
- Verbs to Methods
- Variations to Interfaces
- UML Diagram
- Final Code
Source: https://dev.to/roshan_singh_dd54d52bbaa7/lld-design-process-from-requirements-to-code-594m