1

I have checked many articles and discussions around the web.

So we have the main diagram:

Uncle Bob's Clean Architecture Diagram

So we have Controller pointing directly to RequestModel.

So straight to the point, should I:

  1. Create a RequestModel class on "delivery" (is how uncle bob calls this layer) layer that implements a RequestModel interface, create the instance of RequestModel concrete class in controller and "throw it in the flow"
  2. Create a RequestModel class on use-case layer, create the instance of RequestModel class in controller and "throw it in the flow''

From my initial understanding, option 2 violates some SOLID principles, correct?

Christian H
  • 143
  • 4
  • 1
    A request model is not an interface, it's just a data structure that one (or more) of the methods on the InputBoundary interface accept as a parameter. It's declared in the same layer as the use-case, but is created by clients in order to invoke the Interactor (so, as candied_orange said, the controller might create it; it certainly has to pass it along). Note that the request model is a conceptual thing, a representation of an architectural element; it might be an actual class, but it might just be a parameter list. – Filip Milovanović Feb 17 '21 at 08:28
  • Thank you @FilipMilovanović for this – Christian H Feb 18 '21 at 17:34

1 Answers1

2

Controller creates a RequestModel instance or implements RequestModel?

Let's read a bit from Uncle Bobs book:

Open arrowheads are using relationships. Closed arrowheads are implements or inheritance relationships

Clean Architecture by Robert Martin - page 84

There is no closed arrow head between Controller and RequestModel so no implementing relationship. There is an open arrow head. So a Controller may use a RequestModel.

Does that mean Controller creates a RequestModel? Well it can. Or you can inject it. The diagram simply doesn't tell you which. But for sure there's no implementing happening between them. Not and end up with this diagram.

candied_orange
  • 102,279
  • 24
  • 197
  • 315
  • Thank you so much @candied_orange. I was thinking about injecting the mapper(aka adapter) that does the mapping from the request received to the Request Model data object. – Christian H Feb 18 '21 at 17:34
  • 1
    Welcome. Mr. Martin is silent on how to construct Clean Architecture. If you want to learn about construction and dependency injection (the fancy new name for reference passing) I recommend reading [Mark Seemann](https://blog.ploeh.dk/2014/06/10/pure-di/) and [Martin Fowler](https://martinfowler.com/articles/injection.html). [I've also written a little reference implementation](https://codereview.stackexchange.com/questions/148809/a-button-as-a-clean-architecture-plugin). – candied_orange Feb 18 '21 at 18:50
  • 1
    I've also written a bit about [the order to use to construct CA when your objects are immutable](https://softwareengineering.stackexchange.com/questions/371966/is-clean-architecture-by-bob-martin-a-rule-of-thumb-for-all-architectures-or-i/371973#371973). – candied_orange Feb 18 '21 at 19:22