Dedian |
|
|||
-- 關注搜索引擎的開發 |
日歷
統計
導航常用鏈接留言簿(8)隨筆分類(45)
隨筆檔案(82)
文章檔案(2)Java Spaces搜索積分與排名
最新評論
閱讀排行榜評論排行榜 |
Purpose:
Compose objects into tree structures to represent part-whole hierarchies. Composite lets clients treat individual objects and compostions of objects uniformly. Structure: The composite object contains other primitive objects(or say Components), and has the same operation as in those primitive objects. Thus we can operater the composite object with the same operations as a whole. Or in other word, composite object is a container of primitive ojects and itself is derived from same base (abstract) class as primitives, so that it can have same operations as primitives. Actually, we can say that the abstract class represents both primitives and their containers Implementation: -- Extend a base class that represents primitive objects. And the same operation(override function) will be implemented by iterating over that collection and invoking the appropriate method for each component in the collection. -- Add & Remove function (for component collection) will be defined in base class, though it is meaninglessful for leaf classes. reference: http://www.javaworld.com/javaworld/jw-09-2002/jw-0913-designpatterns.html http://www.codeproject.com/useritems/Composite.asp example: http://java.sun.com/blueprints/patterns/CompositeView.html
|
![]() |
|
Copyright © Dedian | Powered by: 博客園 模板提供:滬江博客 |