开发者

Strategy Pattern replacing if/else or case statments

Why does it seem to me that using Strategy is just putting off the if/else to the Factory? 开发者_如何转开发Using Strategy, doesn't a Factory need to figure out which concrete class to instantiate, and doesn't it do so by if/else?

Is another option to use a Map/List somehow, and have the keys be a name of the class to instantiate, and maybe have the class using the Factory pass in a name?


Map\List is an implemetation of Factory pattern.

Using Strategy patter is better than if\else because it's creates les coupled code. With Factory+Startegy you can extend algorithms of processing without touch of client code, and have more ways to configure code dynamicaly (withot recompile).

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜