组合模式在层级数据递归操作中应用.pdfVIP

  • 0
  • 0
  • 约1.3千字
  • 约 2页
  • 2026-09-29 发布于北京
  • 举报

组合模式在层级数据递归操作中应用.pdf

composite模式

场景:

(1)父部门-子部门-子部门

(2)我们要对部门树,删除一个父部门以及其下所有的子部门

publicclassComponent{

publicvoidoperate();

publicvoidaddChild(Componentchild){

}

publicvoidremoveChild(Componentchild){

}

publicComponentgetChildren(intindex){

}

}

publicclassCompositeextendsComponent{

privateListComponentchildren=new

ArrayListComponent();

publicvoidaddChild(Componentchild){

children.add(child);

}

文档评论(0)

1亿VIP精品文档

相关文档