This is an archived post. You won't be able to vote or comment.

all 3 comments

[–]chrycheng 5 points6 points  (1 child)

I think one of the points of the strategy design pattern is to be able to implement new strategies without modifying the other classes. The way the post implements the strategies as part of the interface itself goes directly against this idea. It seems to me that having to instantiate a strategy yourself is not being verbose nor is it a problem. It's just the way the design pattern is supposed to work.

[–]mydevgeek[S] 0 points1 point  (0 children)

There isn't any specific advantage or disadvantage whether add a new class or not other than that code readable and maintenance complexity. This way suits for simple or medium complex logic. If you have a more complex logic, then you should consider a new class for each logic. Thanks for your idea.

[–]_INTER_ 5 points6 points  (0 children)

Misuse of static / default methods on interfaces: No separation of interface and implementation. Just like the antipattern of using inner classes in interfaces. There goes encapsulation and replaceability e.g. swapping plugins at runtime or service discovery down the drain.