I have a question about the two operations that you usually see in the Composite class diagram example.
* GetDescendents
* GetChild (int)
A common example is files and directories, I will stick to this. Assume Size is of interest, so File is the actual size, and Directory is the size obtained from the recursive iteration of GetDescendents. So far, so good. My question is about how customers use GetDescendents. Suppose you need files in a directory that are images for a specific operation. Therefore, in practice, you use some combination of GetDescendents and Children to return imageFiles (depending on whether the client needs all the attached image files or only at the root level).
So, question number one: will you probably not have the GetImageFiles method on the composite, and not so that the client understands it? And is it supposing that GetDescendents are ever practical to expose callers (like ImageViewer) outside of composition?
The second question is about GetChild (int); int int position index to return one child? Depth level in GetDescendents? What will be an example of how the client will use this method?
Cheers
Berryl
design-patterns composite
Berryl
source share