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*
- 6Even when you do end up with multiple uses of the enum, there's still a relatively straightforward fix to that: Use the "real" (OOP) strategy pattern, and write a function (method) that converts your enum values into strategy objects. Then, for each place where you would have interpreted the enum values, you instead make a polymorphic call into the strategy object. The language enforces that every abstract method must be overridden in all concrete subclasses, so you cannot "forget" one of the methods. In this way, the enum still exists, but you only interpret it once.Kevin– Kevin2021-10-08 21:14:44 +00:00Commented Oct 8, 2021 at 21:14
- 23This is not a Strategy pattern In a proper strategy pattern, the algorithm is contained outside the dispatcher logic, and passed in, typically using an interface. Allowing near infinite possibilities to extend the code. Here the algorithm is inside existing code, and the enum just chooses. There is no way to extend, for the outside to provide a whole new algorithm. E.g. see tutorialspoint.com/design_pattern/strategy_pattern.htmuser949300– user9493002021-10-09 15:56:06 +00:00Commented Oct 9, 2021 at 15:56
- 3Not sure why this answer is so highly upvoted. This answer focuses on how it might, technically, fit the definition of a strategy pattern in a none-OOP setting (and, as @user949300 said, that is debatable). It ignores that in an OOP setting it is definitely an anti-pattern, and should be tackled in some other way.Omegastick– Omegastick2021-10-10 12:41:17 +00:00Commented Oct 10, 2021 at 12:41
- 2@Omegastick, I'd suggest it's highly upvoted because most people think you mistaken in your view that it is an anti-pattern.David Arno– David Arno2021-10-10 12:53:33 +00:00Commented Oct 10, 2021 at 12:53
- 2It is not a strategy pattern if you just invoke a function statically in the code, but it can be a strategy pattern if the function can be chosen dynamically, for that you would need to resort to e.g. high-order programming.edalorzo– edalorzo2021-10-10 14:56:32 +00:00Commented Oct 10, 2021 at 14:56
| Show 4 more comments
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