组合在 PHP 中的实现
Composite is a structural design pattern that allows composing objects into a tree-like structure and work with the it as if it was a singular object.
Composite became a pretty popular solution for the most problems that require building a tree structure. Composite's great feature is the ability to run methods recursively over the whole tree structure and sum up the results.
在 PHP 中使用模式
Usage examples: The Composite pattern is commonly used when working with object trees. The simplest example would be applying the pattern to elements of the DOM tree, working with the composite and simple elements of the tree in the same way.