Skip to content

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Correct approach for different types of concept? #63

Closed
ErlanBazarov opened this issue Aug 6, 2022 · 1 comment
Closed

Correct approach for different types of concept? #63

ErlanBazarov opened this issue Aug 6, 2022 · 1 comment

Comments

@ErlanBazarov
Copy link

Let's say we have two concepts: Book and BookBeingSold. Book have methods like read, rate, and have properties like title and author. BookBeingSold have the same methods and properties but it also have additional methods buy, cancel, changePrice, and property price. The database have two tables books (id, title, author) and books-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 and bookBeingSold and two separate repositories? Should we inherit one module from another? Or we should just have one module book and one repository?

@Sairyss
Copy link
Owner

Sairyss commented Aug 6, 2022

I think you are mixing up two completely different concepts:

  1. A Book that has its set of properties like author and title and can be read
  2. Something that has a price and can be sold, no matter what it is, it can be a Book or a Pencil. lets call it a Product.

Each have it's own unrelated business logic. Why you need a BookBeingSold with the same methods as a Book? You can just have 2 separate entities:

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 {...}
}

rate method that you mentioned belongs to a Product too IMO and not to a Book (unless your Book has non-generic ways of rating it that are different from other Products).

With this approach you can add more products, not only books.
The key of DDD is analyzing and defining proper bounded contexts for each entity/aggregate/module. Book and Product are two unrelated concepts that shouldn't be mixed.

Repository owner locked and limited conversation to collaborators Aug 6, 2022
@Sairyss Sairyss converted this issue into discussion #64 Aug 6, 2022

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants