13 Nov 2023
Intermediate
Here are some real-world examples of entities in domain-driven design:
- E-commerce:
- Product: Represents a tangible or digital item available for purchase. It has attributes like name, description, price, and stock quantity.
- Customer: Represents an individual or organization that can browse and make purchases on the e-commerce platform. It typically has attributes like name, email, and shipping address.
- Order: Represents a customer's request to purchase one or more products. It contains information like order number, customer, and order status.
- OrderItem: Represents an individual item within an order, including the product, quantity, and price.
- ShoppingCart: Represents a temporary storage of products that a customer is interested in purchasing before finalizing the order.
class Product {
String productId;
String name;
String description;
double price;
int stockQuantity;
}
class Customer {
String customerId;
String name;
String email;
String shippingAddress;
}
class Order {
String orderId;
Customer customer;
List<OrderItem> orderItems;
String status;
}
class OrderItem {
Product product;
int quantity;
double price;
}
class ShoppingCart {
Customer customer;
List<Product> products;
}
- Banking:
- Account: Represents a customer's bank account, such as savings or checking. It has a unique account number and properties like balance, owner, and transaction history.
- Customer: Represents an individual or organization that has an account with the bank. It includes information like name, contact details, and accounts owned.
- Transaction: Represents a financial transaction that affects one or more accounts. It includes details like transaction ID, amount, date, and the involved accounts.
class Account {
String accountId;
Customer customer;
double balance;
List<Transaction> transactions;
}
class Customer {
String customerId;
String name;
List<Account> accounts;
}
class Transaction {
String transactionId;
Date date;
double amount;
Account fromAccount;
Account toAccount;
}
- Healthcare:
- Patient: Represents an individual who receives medical care. It has attributes like patient ID, name, date of birth, and medical history.
- Appointment: Represents a scheduled meeting between a patient and a healthcare provider. It includes details like appointment date, time, patient, and provider.
- Procedure: Represents a medical procedure or treatment that a patient undergoes. It includes information such as the procedure code, description, and date.
class Patient {
String patientId;
String name;
Date dateOfBirth;
List<Appointment> appointments;
List<Procedure> procedures;
}
class Appointment {
String appointmentId;
Date dateTime;
Patient patient;
Doctor doctor;
}
class Procedure {
String procedureCode;
String description;
Date date;
Patient patient;
}
- Social Media:
- User: Represents an individual using the social media platform. It includes information like username, profile details, and a list of posts and comments associated with the user.
- Post: Represents a user's content shared on the platform, such as text, images, or videos. It includes attributes like post ID, content, and timestamp.
- Comment: Represents a user's response to a post. It includes information like comment ID, content, and the user who made the comment.
class User {
String userId;
String username;
String profileDetails;
List<Post> posts;
List<Comment> comments;
}
class Post {
String postId;
String content;
Date timestamp;
User user;
}
class Comment {
String commentId;
String content;
Date timestamp;
User user;
}
- Education:
- Student: Represents an individual enrolled in an educational institution. It includes attributes like student ID, name, contact information, and enrollment status.
- Course: Represents an academic course offered by the institution. It includes details like course code, title, instructor, and a list of enrolled students.
- Enrollment: Represents a student's registration in a specific course. It contains information like enrollment ID, student, course, and enrollment status.
class Student {
String studentId;
String name;
String contactInfo;
List<Enrollment> enrollments;
}
class Course {
String courseId;
String title;
String instructor;
List<Student> enrolledStudents;
}
class Enrollment {
String enrollmentId;
Student student;
Course course;
String status;
}
These entities are central to their respective domains and play a key role in modeling and managing the domain's core concepts and data.