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.

Required fields*

5
  • 1
    Not to be a smart aleck but the term "good" is not an engineering term so it is very hard to tell you if a design is good or not without defining it. If you're asking "Does this design allow me to re-use objects?" then the answer is yes. I don't know that object re-use is all that important-- in fact it may introduce more code errors as you have to manage both the life cycle of the instance and its state. Do you see some advantage of this compared to using a new object instance each time? Commented Aug 8, 2023 at 20:33
  • There is no inherit problem with such a design. The issue is bring able to correctly handle state transitions between closed state and opened state. This is why it's technically easier to use a different instance, you only need to deal when the opened-closed transition, and not closed - opened. Commented Aug 9, 2023 at 7:37
  • I see @JohnWu but what about IoC for the injection of dependencies? The constructor shouldn´t be used to pass a parameter like "filePath" I believe. Commented Aug 9, 2023 at 8:27
  • 1
    @Nmaster88 The factory pattern can help with calling a constructor which has got some DI parameters and some "runtime" parameters (for lack of a better word). This allows you to have the best of both worlds. Commented Aug 9, 2023 at 9:08
  • @Flater I see, Im already making a StreamReaderWrapperFactory call in the Open method, which is responsible to return the actual instance of StreamReader. But if we use IoC and call an endpoint the instance of CsvWriterService I mention will be created by the framework, so how can I pass a runtime parameter like "filePath" without creating a standalone method? The only way is to force the user to do the instantiation of the class itself, which might be the right way. Commented Aug 9, 2023 at 10:26