What are the known “gotchas” with regards to the Chain of Responsibilty pattern?

前端 未结 2 1650
天涯浪人
天涯浪人 2021-02-19 17:55

I have been finding myself using the Chain of Responsibility pattern often (3 times is often for me) in my current project and I\'m wondering if I have become a little over-enth

2条回答
  •  春和景丽
    2021-02-19 18:49

    I think it is fair to say that in general it is worth using a given design pattern if it gives you more benefits then costs. Every pattern introduces extra level of indirection in the code, so it is more difficult to follow, especially for junior members of the team. Having said that I think that the Chain of Responsibility pattern is definitely useful if you don't know upfront what are the classes going to be that are going to do the processing (so being in the chain), or you reuse these classes in different contexts, create different chains in different scenarios, etc.

    In general I think it is pretty bad to over-engineer your solutions (because as you said new people struggle with understanding it), but there are some cases where the design patterns are very useful.

提交回复
热议问题