I have a Python project where I have a Car class that has a main state machine with multiple states. Moreover, The Car class has multiple systems. These systems are Engine, GearBox, Brakes, Dashboard, Stereo and a few more. During the transition of each state, I have entry and exit action which do something with these systems. But aside from this I should be able to control the systems separately as well by checking in which state I am at the moment.
As you can see I have multiple systems and passing them as a dependency injection to my Car class leads to constructor bloating which indicates too many responsibilities. This problem I need to solve.
I tried to solve this by moving similar systems behind a facade class but the issue I find here is that for some of the systems, the components that make these systems need to be controller separately as well. An example here:
We have a system that consists of 2 more systems. In the facade I can call a method activate system and that method will have the two systems behind this facade system be activated but sometimes I need to be able to activate them separately from each other. Now, I could just have 2 more methods activating each system separately in the facade class but that kind of feels to me that I am breaking the principle behind the facade pattern.
I guess in general I could explain my problem as such where I have a class that has many dependencies that are needed and I try to move them behind facades but after some facades there is more behaviour I need to call directly in the main class but then that makes my code really nested with multiple facades within facades.
Looks like you’ve landed in clean-code hell :) This “bloat” is typical when you try to inject everything. it’s so typical that there are objects that handle this injection, and they are called “dependency injectors” for the surprise of no one. See this project for example.
I’d try to simplify, honestly. I wouldn’t inject absolutely everything, unless this is a project to learn about unit testing, abstractions or your professor/tech lead is really a purist.
Remember that premature abstraction (and optimization) is the root of all evil.