Skip to content
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

Why to use separate ProductId classes for different parts of the system? #1

Closed
elnurvl opened this issue Apr 10, 2021 · 3 comments
Closed

Comments

@elnurvl
Copy link

elnurvl commented Apr 10, 2021

I see the ProductId is always implemented the same way regardless of being used in different subdomains. So what is the motivation behind code duplication?

I also noticed that the ...Id classes are implemented with the same logic in general. Wouldn't it be better if we had an abstract Id class and the concrete classes inherited from it?

@ttulka
Copy link
Owner

ttulka commented Apr 11, 2021

I prefer the "share nothing" philosophy. IMO a bit of duplication is better than a shared lib that needs to be maintained, versioned, ...
In my experience, code that has begun as a piece of duplication evolved in separated ways eventually. Beginning with a shared library per default would kill such an option.
The example services are implemented quite similarly, but just imagine a different kind of database (NoSQL) used in one of them. In that case, the ProductId implementations would differ from each other.

@elnurvl
Copy link
Author

elnurvl commented Apr 11, 2021

The example services are implemented quite similarly, but just imagine a different kind of database (NoSQL) used in one of them. In that case, the ProductId implementations would differ from each other.

@ttulka , I understand your points, but I see the examples you are giving can be handled by abstractions. In general, I think if the domain layer represents the model of the business/problem, the components of it correspond to the real-world concepts related to that business, therefore, should be consistent throughout the application. For instance, it makes more sense for the Accounting, Sales, Product subdomains to use the same Money value object. The implementation details should be the responsibility of DTO's and mappers.

These are my views on the topic. I would be happy to hear your objections against these arguments.

@ttulka
Copy link
Owner

ttulka commented Apr 12, 2021

@elnurvl I am not sure, what you mean by "abstraction"...? If you mean an interface ProductId with concrete implementations in particular services, I think this would be a correct approach. I'm used to taking a shortcut to save some typing where I don't see a clear benefit (and I do see drawbacks such as a shared lib) to avoid an explosion of not particularly useful interfaces, but it would be conceptually okay.
Money is a different thing because it is a truly reusable component. That's why I did implement it as a common lib class.

@ttulka ttulka closed this as completed Apr 23, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants