DEV Community

Discussion on: Example of the Strategy Pattern

Collapse
 
jamarino profile image
jamarino

I believe what you are describing is the repository pattern. A data store abstraction.

In my understanding, a strategy pattern is supposed to offer different behaviour with a common interface. Usually the example has to do with calculating prices where one strategy may apply on weekdays and another might apply discounts for happy hour. This gives you the ability to change program behaviour on runtime.

Collapse
 
cwl157 profile image
Carl Layton

I have updated the post based on your feedback to apply the strategy pattern to importing data into an application from different sources.

Collapse
 
jamarino profile image
jamarino

Much better example now, great effort!

Collapse
 
cwl157 profile image
Carl Layton

Great observation! In the context of this post, the strategy pattern could be used to import data from a csv file or xml file. The program would figure out which file type is being imported and apply the correct strategy. I will unpublish and make those adjustments. Thank you for the feedback!