5

In his blog post The Clean Architecture Uncle Bob suggests a 4-layer architecture. I understand the separation between business rules, interfaces and infrastructure, but I wonder if/when it's necessary to have separate layers for domain objects and use cases. What added value will it bring, compared to just having the uses cases as "domain services" in the domain layer?

The only useful info I've found on the web about a use case layer is an article by Martin Fowler, who seems to contradict Uncle Bob about its necessity:

At some point I may run into the problems, and then I'll make a Use Case Controller - but only then. And even when I do that I rarely consider the Use Case Controllers to occupy a separate layer in the system architecture.

Edit:

I stumbled upon a video of Uncle Bob's Architecture: The Lost Years keynote, in which he explains this architecture in depth. Very informative.

5

I disagree with Uncle Bob's use of the term "use case" but I understand what he's getting at. I don't really want to quibble over the semantics of the term in any case.

For the sake of this question, use cases are application specific business rules.

Your question is really "when are separate layers needed for both enterprise business rules and application specific business rules?" And the quick answer is you need them when your application grows large enough to justify it.

If there are a small number of rules from either set, then it's just as easy to keep the implementation of those rules within a single application layer. If there are lots of rules for both sets, then you'll want to break them out to specific layers.

Uncle Bob lays out a rule that the inner circles shouldn't know of the outer circles in his architectural diagram. And that's ultimately the answer to your question. As the rules evolve and have clear delineation from the others then you'll need to isolate them out to separate layers.

0

I'm no expert on the subject, but this is the way I understand it. The idea with a separate layer for the domain objects and the use case objects is you may eventually have a need to implement multiple versions of the use case object layer for applications that should have a different behavior, but follow the same enterprise rules. The way he explains it is the innermost layer is the enterprise rules, and the user case layer is the application behavior rules.

Whether you agree with Uncle Bob or not, in my opinion the answer provided by @GlenH7 is not in the spirit of what Uncle Bob is promoting. He does not want you to wait until your application grows larger before you separate the layers. He wants iteration zero to be when you design how you will keep the architectural layers separate and decoupled. The idea is that once a need to swap out a layer arises, you should be able to act upon that need quickly and easily because you already separated the layers before hand. If you wait until the application grows larger or the need to separate the layers arises, you probably won't actually do it because it is too much work. But if you make it easy you will do it just because you are curious to see what would happen if you swapped out a layer with an alternate one.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.