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*
-
1Not 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?John Wu– John Wu2023-08-08 20:33:51 +00:00Commented 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.Ccm– Ccm2023-08-09 07:37:22 +00:00Commented 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.Nmaster88– Nmaster882023-08-09 08:27:04 +00:00Commented 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.Flater– Flater2023-08-09 09:08:47 +00:00Commented 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.Nmaster88– Nmaster882023-08-09 10:26:10 +00:00Commented Aug 9, 2023 at 10:26
Add a comment
|
How to Edit
- Correct minor typos or mistakes
- Clarify meaning without changing it
- Add related resources or links
- Always respect the author’s intent
- Don’t use edits to reply to the author
How to Format
-
create code fences with backticks ` or tildes ~
```
like so
``` -
add language identifier to highlight code
```python
def function(foo):
print(foo)
``` - put returns between paragraphs
- for linebreak add 2 spaces at end
- _italic_ or **bold**
- indent code by 4 spaces
- backtick escapes
`like _so_` - quote by placing > at start of line
- to make links (use https whenever possible)
<https://example.com>[example](https://example.com)<a href="https://example.com">example</a>
How to Tag
A tag is a keyword or label that categorizes your question with other, similar questions. Choose one or more (up to 5) tags that will help answerers to find and interpret your question.
- complete the sentence: my question is about...
- use tags that describe things or concepts that are essential, not incidental to your question
- favor using existing popular tags
- read the descriptions that appear below the tag
If your question is primarily about a topic for which you can't find a tag:
- combine multiple words into single-words with hyphens (e.g. design-patterns), up to a maximum of 35 characters
- creating new tags is a privilege; if you can't yet create a tag you need, then post this question without it, then ask the community to create it for you