Having recently opened dependency injection, I am now trying to understand how often and how far it can take.
For example, let's say that I have a dialog box in which the user asks for registration data - name, surname, phone number, serial number - thatโs what. Data must be verified in various ways (for example, that the first and last name are not empty, and the serial number is a certain length). After verification, it should be cached on the local computer, and also sent to the registration server. The dialog should be closed only after all these things are successful, or the user cancels.
So, maybe there are four things that we are trying to achieve here (responsibilities): user interface, verification, local caching, sending data to a non-local server.
What is the responsibility for the dialogue and what needs to be introduced? Obviously, the user interface is in the dialog box, but should validation, caching, and data transfer be introduced? I think they do, otherwise the dialog class needs to know about the logic of the data fields in order to validate, it needs to know how and where to cache data, as well as how to send data somewhere. If so, this can lead to some hefty code at the end of the caller (assuming we are injecting through a constructor, which I think is preferable to setter functions), for example.
MyDialog dlg(new validator(), new cacher(), new sender());
, , ? , , , , . , - , , , - " "?
, , . DI .