Java OOD object oriented design-Composite Pattern

Composite Pattern

-The pattern consists of three classes: the Composite (the node that can have children), the Leaf (no children), and the Component, which is a superclass extended by both the Composite and Leaf.

-The Composite has a collection of Components, so that the Composite class can loop through those Components without keeping track of whether the Component is actually a Composite or a Leaf.

-The Composite also has an addComponent method so that Components can be added to its contents.在这里插入图片描述

猜你喜欢

转载自blog.csdn.net/Nick_kn/article/details/109708298
今日推荐