Correct approach for different types of concept? #64
Replies: 1 comment
-
I think you are mixing up two completely different concepts:
Each have it's own unrelated business logic. Why you need a a Book: class Book {
id: string;
author: string;
title: string;
read() {...}
} And a Product (you can call it differently): class Product {
price: number;
productType: string; // <- product type is a "book" here
productId: string; // <- book id
buy() {...}
cancel {...}
changePrice {...}
}
With this approach you can add more products, not only books. |
Beta Was this translation helpful? Give feedback.
-
Let's say we have two concepts:
Book
andBookBeingSold
.Book
have methods likeread
,rate
, and have properties liketitle
andauthor
.BookBeingSold
have the same methods and properties but it also have additional methodsbuy
,cancel
,changePrice
, and propertyprice
. The database have two tablesbooks
(id, title, author) andbooks-being-sold
(id, book_id, price, is_deleted).What should code look like for this scenario in DDD way? Should we create two separate modules
book
andbookBeingSold
and two separate repositories? Should we inherit one module from another? Or we should just have one modulebook
and one repository?Beta Was this translation helpful? Give feedback.
All reactions