我们经常可能要递归构建树状的组合结构,此模式提供了很好的解决方案
Leaf *l = new Leaf();
l->Operation();
Composite *com = new Composite();
com->Add(l);
com->Operation(); 调用LEAF方法
Component *ll = com->GetChild(0);
ll->Operation(); 调用LEAF方法
我们经常可能要递归构建树状的组合结构,此模式提供了很好的解决方案
Leaf *l = new Leaf();
l->Operation();
Composite *com = new Composite();
com->Add(l);
com->Operation(); 调用LEAF方法
Component *ll = com->GetChild(0);
ll->Operation(); 调用LEAF方法