educative.io

How about having the same entity used in different modules?

Hi,

I am progressing on “Hexagonal Software Architecture for Web Applications” and at point when authors point out one approach is better than another. It requires bit of more discussion as to build a better perspective and build a solid foundation on top of the course.

For example in the lesson “Architecturally Expressive Package Structure”, the author suggested for new package structure.

But how about having the same entity used in different modules? Are we not violating DRY? What if I want to reuse some service?

I believe it would be nice if educative provide open platform like Udemy where we can ask question and author can answer. This will help us to learn better and author to evolve his content.

Regards,
Chandraprakash Sarathe

In the ideal hexagonal world, you would only use the same entity and services within the same bounded context (or “hexagon”). I.e. it would be an architectural goal not to reuse entities and services outside of a context (in the example that context would be the “account” context. Instead, the context would provide input adapters to interact with the entity or service in question.

And yes, with a “clean architecture” like this we will be violating DRY at some point. That’s the trade-off: either we re-use classes across boundaries, which will make the code tightly coupled and harder to maintain over time, or we duplicate some data structures across multiple bounded contexts, but keep the contexts loosely coupled.

That said, I haven’t seen the “perfect” architecture, yet, so there’s always a middle ground :).

-Tom

Thanks Tom for clarification and pointing towards ttade offs. This makes sense

Keep up the good work