Prerequisites
To get the most out of this post, it helps if you have a basic understanding of object oriented programming and inheritanc...
For further actions, you may consider blocking this person and/or reporting abuse
This is one of my favorite patterns to use with things like manufacturing lines and work cells where there is a lot of common activity (barcode reading, inventory control, etc) but the implementation details vary to some degree from work area to area.
Hey Frank, I know this is super old, but do you happen to have any examples around of the use case you described? I'm building basically the same type of system for manufacturing lines and trying to tackle the issue without blowing up our config files further. Also, for the first time, we'll have to conditionally load extern dll's in each strategy also, so I don't know how to prevent bundling in every extern dll into my deployment binaries.
Very nice post with a descriptive example of usage. Real life examples always are adding additional value to an example. I'm a big fan of design patterns too so I enjoyed this post.
Personally I'd change inheritance to composition for ShouldDelete method, but once again great article.
Could you make an example?
Sure.
Instead of inheriting from a base class and method overriding like here:
You add the class variable of a given class and calls it's method if needed.
More about the comparison between Inheritance and Composition you can find here. Take a closer look at the table at the end of article.
Generally speaking, I am curious, how can one do automatic tests on this pattern?
First step would be to test each strategy implementation I presume.
Second would be to test if the correct strategy was selected based on the input?
That’s how I’d do it, Unit test the concrete implementations, and selection, then Integration test both.
I used to do similar things, but for task that have a very similar output/process, I tend to use a "DeleteOption" argument to keep the process centralised. I find it easier to then save the parameters with a DataContract.
I guess you use a dictionnary to select the correct function? I usually do this for very unrelated tasks:
IDictionnary <myEnum.MethodName, myIAction>
. Then it is as well quite easy to save it.
Great write up Sam! This is one of my favorite programming patterns to use and it can be applied it a lot of different languages. I wrote a post about the strategy pattern as well if folks are looking for more examples.
Nice article sir! Thank you.
We are implementing data integration with netsuite. We are in process of using any good design pattern. What is best suggestion for data integration.
Domain is e-commerce.