Timeline for I wrote a class with "init" method. Should I call it from other class methods? Or leave it to the object user? (Code Design)
Current License: CC BY-SA 4.0
6 events
| when toggle format | what | by | license | comment | |
|---|---|---|---|---|---|
| Apr 25, 2023 at 12:47 | comment | added | joker | Would you please elaborate more on "If it's a single instance you might be interested in frequent readiness checks in order to handle denials of service gracefully. In this case you handle the availability from different components while keeping consumers agnostic to these details."? I didn't quite catch that. | |
| Apr 21, 2023 at 23:12 | comment | added | Laiv | If the component is indeed like a Thread then it's created every time and the init seems reasonable. If it's a single instance you might be interested in frequent readiness checks in order to handle denials of service gracefully. In this case you handle the availability from different components while keeping consumers agnostic to these details. | |
| Apr 21, 2023 at 16:43 | comment | added | joker | Plus we have to factor in that the database which the service performs checks against might be down at some times. We need only to fail requests that happen to be invoked when the database is down. If we only allow init to be called upon instantiation, and the database happens to be down at the time but brought back up at later point int time, we risk losing all future requests. | |
| Apr 21, 2023 at 16:40 | comment | added | joker | I don't like, however, the idea of factory or builder here. The problem doesn't fit in any of the two patterns. Normally, factories and builders are for pojos (objects construction i.e., instantiation and setting variables). In my case, the object, in terms of construction is perfectly fine without initialization. This is strictly in terms of construction/instantiation and not initialization. Maybe think of a Thread. You can instantiate one, but it's almost not usable until you call start | |
| Apr 21, 2023 at 16:38 | comment | added | joker | You are correct, for the most part. It's true that I don't have a use case or requirement. So, nice catch. I have to give you that. You are also correct about not providing too many options. And yes, I'm building sort of a library to be used in the main application. | |
| Apr 21, 2023 at 15:25 | history | answered | Laiv | CC BY-SA 4.0 |