This might be an easy question for experienced software engineers.
I'm currently reading the book Clean Architecture by Uncle Bob, and I'm trying to implement clean architecture in a Java project.
Now, in my project, I came across the exact same situation as described here in Chapter 17 of the book:
The red line is the boundary between the high-level business rules component and the low-level database component. Thanks to the
DatabaseInterface, that is part of the high-level component, but implemented in the low-level component, the dependency rule is satisfied.
However, how can the
BusinessRules get an instance of an object that implements
DatabaseInterface without violating the dependency rule?
The implementing class
DatabaseAccess is in the low-level component, and the high-level component is not supposed to know anything about the classes in the low-level component.
In other words, we can't instantiate a
DatabaseAccess object inside
BusinessRules, because this would violate the dependency rule.
How is this problem generally solved?
The same situation is also described in Chapter 18:
And here again, how can
Client get an instance of
ServiceImpl without violating the dependency rule?
The book doesn't give any hints about how this is done in practice. I would be very interested to know what's the correct strategy for solving this situation.