This is a very open question, so my answer will be as general as possible ...
Performing work in designers is not as "bad" as before, when exception handling was not as common and developed as it is today. You will notice that in a conversation with Google Tech, designers are mainly considered in terms of testing. It was very difficult for the designers to debug the story, so it’s saying correctly that it’s better to do as little as possible in the designer.
With that said, you will notice that it also affects the implementation dependency / vendor pattern, which is notorious for complex constructors. In this case, it is preferable to leave ONLY the provider / DI code in the constructor. Again, the answer depends on what patterns you use and how your code "fits" together.
The whole purpose of using the constructor is to create a neat object that can be used immediately; those. new Student("David Titarenco", "Senior", 3.5) . There is no need to do david.initialize() , as that would be completely stupid.
Here are some of my production code, for example:
Config Conf = new Config(); Log.info("Loading server.conf"); Conf.doConfig();
In the above case, I decided not to do anything with the constructor (it is empty), but it has a doConfig() method that runs the entire i / o disk; I often thought that the doConfig() method is simply pointless, and I have to do everything in the constructor. (I will only check the configuration file once, after all.)
I think that it completely depends on your code, and you should not think that putting "stuff" in your constructor is bad. What are the designers for! Sometimes we get getThis OOP ( getThis , setThat , doBark ), when the whole class really needs to do this, load the configuration file. In such cases, just put everything in the constructor and name it day!
David Titarenco Aug 13 2018-11-11T00: 00Z
source share