Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

5
  • 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. Commented Apr 21, 2023 at 16:38
  • 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 Commented Apr 21, 2023 at 16:40
  • 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. Commented Apr 21, 2023 at 16:43
  • 1
    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. Commented Apr 21, 2023 at 23:12
  • 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. Commented Apr 25, 2023 at 12:47