Cyclic Code Dependencies
In the previous section, I talked about execution flow. It should be easy to trace the flow of control. Likewise,
it should be clear what each step along the way is doing. Cyclic code dependencies, though, can totally muddy the water.
I'll give an example based on a similar real life example. In this example, we have a Dog class and a DogService
class. When we encounter this kind of pattern, it tends to be an
Anemic Domain Model.
The business logic is in the service and the entity only stores the data. The service depends on the entity, not the
other way around. In this real life example that I'm imitating, though, that wasn't the case. The DogService
would make a call to the Dog along pass itself along to the Dog. The Dog would then call the
DogService which again might call a function on the Dog. The execution flow would simply bounce
back and forth. I'll keep this simple: Don't Do That.
©
Donald A. Barre. All rights reserved.