In the strategy pattern can the strategy take the Context as parameter

后端 未结 4 1414

Feedback summary

I will now close this thead (I think there will be no more feedback) and try to summarize what I understood

  1. using the \"Contex
4条回答
  •  没有蜡笔的小新
    2020-12-31 11:04

    Your code is your code, write whatever makes sense for you. However, I do have a word of caution.

    The purpose of the strategy pattern is to create a family of strategies that can be interchangeable. Like many design patterns it derives its benefit from decoupling. In this case we are decoupling behavior from the class that uses such behavior.

    When a strategy takes the context as an argument, decoupling is reduced. Changes in Context may require changes in your strategy implementations. Like a previous poster noted, it may be best to look for a way to keep them decoupled.

    That being said, as long as your intent is to allow strategies to be interchangeable and your code accomplishes that intent, then I don't see a problem.

提交回复
热议问题