Imagine someone gives you this requirement:
Build an Online Shopping System.Most developers immediately start creating classes:
class User{};
class Product{};
class Order{};But an important question remains unanswered:
Why are these the right classes?Or consider:
Build a Hotel Booking System.Should we create:
class Hotel {};
class Room {};
class Reservation {};Probably.
But how do we know?
How do we discover the important concepts?
How do we know which concepts deserve classes?
How do we know which concepts are merely attributes?
How do we model business rules correctly?
These questions are the purpose of Domain Modeling.
The Fundamental Idea
Before software exists:
Business ExistsSoftware is merely a model of that business.
Example:
A library exists even without software.
It already contains:
Books
Members
Loans
Reservations
Fines
LibrariansSoftware does not invent these concepts.
Software models them.
Definition
A Domain Model is:
A conceptual representation of important business concepts, relationships, behaviors, and rules.
Notce:
Conceptual Representation
Not:
Database Design
Code Design
API DesignThose come later.
Domain Modeling vs Database Modeling
Domain Modeling
Focuses on:
Business Concepts
Business Rules
Responsibilities
RelationshipsExample:
Customer places OrderDatabase Modeling
Focuses on:
Tables
Columns
Indexes
Foreign KeysExample:
customers
orders
order_itemsImportant Rule
Never start with database tables.
Start with business concepts.
Real-World Analogy
Imagine an architect designing a hospital.
They first think:
Patients
Doctors
Nurses
Departments
AppointmentsNot:
Concrete
Steel
Electrical WiringThose details come later.
Software design works the same way.
Understanding the Domain
Before modeling:
You must understand the business.
Example:
Requirement:
Customers can order food from restaurants.
Restaurants prepare food.
Delivery partners deliver food.
Customers pay online.Before creating classes:
Understand:
Who participates?
What happens?
What rules exist?
What terminology exists?Step 1: Discover Domain Concepts
Let's analyze.
Requirement:
Customers place food orders.
Restaurants prepare food.
Delivery partners deliver food.Potential concepts:
Customer
Restaurant
Order
DeliveryPartner
PaymentThese become domain candidates.
Step 2: Separate Concepts from Attributes
Example:
Customer
Name
Phone Number
AddressQuestion:
Which are concepts?
Answer:
Customer
Question:
What are these?
Name
Phone Number
AddressAnswer:
Attributes
Model:
class Customer
{
private:
string name;
string phone;
string address;
};Step 3: Discover Behaviors
Domain models are not just data.
We must identify behavior.
Cusotmer
Place Order
Cancel Order
Update Address
Order
Calculate Total
Track Status
Mark Paid
Restaurant
Accept Order
Reject Order
Prepare FoodBehavior reveals responsibilities.
Leave a comment
Your email address will not be published. Required fields are marked *


