Is the Composite Pattern SOLID?

前端 未结 4 1443
天涯浪人
天涯浪人 2021-01-02 04:19

A Leaf in the Composite Pattern implements the Component interface, including Add, Remove, and GetChild methods that a Leaf is never g

4条回答
  •  无人及你
    2021-01-02 04:30

    Using Composite lets you to treat all objects uniformly and possibly to get rid of "instanceOf" thing which is a clear sign of a code smell. So it's respecting to LSP (Liskov's) at a first glance. However, as you differentiate common method implementations, it's likely to start to violate LSP. So, IMO, we need to keep that balance.

提交回复
热议问题