Great post sir, I have some points though.
At run time the "ifs and elses" and "_extractors.FirstOrDefault(e => e.UseExtractor(fileExtension));" aproach would have not differences, right? Because all the latter line does, is to get the first "extrator" that first satisfies the condition by doing "ifs and elses" as well...
I think your code would take more advantage of interfaces if it was like this:
publicstring[]Extract(stringfilePath,ITextExtractorextractor){if(extractor!=null){returnextractor.ExtractContent(filePath);}else{thrownewException("unable to extract content");}}
To decide at run time what Strategy to use, you might use some parameterized Factory Method.
Let me know what you think please.
This could certainly work but it loses the benefit of abstracting out the extractors. The idea is that each extractor knows what it can extract and it indicates that with the function that finds it.
This provides nice encapsulation by allowing the class that implements the interface to decide what it can extract.
Your idea would be quite different and more akin to the Factory pattern.
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
Great post sir, I have some points though.
At run time the "ifs and elses" and "_extractors.FirstOrDefault(e => e.UseExtractor(fileExtension));" aproach would have not differences, right? Because all the latter line does, is to get the first "extrator" that first satisfies the condition by doing "ifs and elses" as well...
I think your code would take more advantage of interfaces if it was like this:
To decide at run time what Strategy to use, you might use some parameterized Factory Method.
Let me know what you think please.
This could certainly work but it loses the benefit of abstracting out the extractors. The idea is that each extractor knows what it can extract and it indicates that with the function that finds it.
This provides nice encapsulation by allowing the class that implements the interface to decide what it can extract.
Your idea would be quite different and more akin to the Factory pattern.