什么时候应该使用复合设计模式? [英] When should I use composite design pattern?

查看:257
本文介绍了什么时候应该使用复合设计模式?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我应该使用复合设计模式时,我不明白
我可以从这种设计模式中获得哪些好处?
我访问过这个网站,但它只告诉我关于设计模式的结构,而不是使用它的场景。
我希望对于像我这样开始学习设计模式的程序员是有益的。

I don't understand when I should use composite design pattern. What kinds of benefits will I get from this design pattern? I visited this website but it only tells me about the structure of the design pattern and not the scenarios in which it is used. I hope that it will be beneficial to the programmers like me who are starting to learn design pattern.

推荐答案

引用来自设计模式


Use the Composite pattern when


  • 时,使用复合模式,您想要代表对象的部分整体层次结构。

  • 您希望客户能够忽略
    组成的对象和
    个别对象之间的差异。客户将
    统一处理复合
    结构中的所有对象。

通常的用法是用作本书中的激励例子,图形窗口的显示系统可以包含其他窗口和图形元素(如图像,文本)。组合可以在运行时组合,客户端代码可以操纵所有的元素,而不用担心哪些类型是常用的操作,比如绘图。

A common usage is the one used as a motivating example in the book, a display system of graphic windows which can contain other windows and graphic elements such as images, text. The composite can be composed at run-time, and the client code can manipulate all the elements without concern for which type it is for common operations such as drawing.

这篇关于什么时候应该使用复合设计模式?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆