All right so let's try to summarize some of the things that we've learned about the composite Design
Patterns so we know from experience that objects can generally use other objects either through inheritance
or through composition.
And so then when we're talking about the composite design pattern we're talking about composition rather
than inheritance.
So we know that sometimes some of the composed objects as well as individual objects they actually need
similar or identical behaviors meaning they need similar API to be available on both of them.
So that's where the composite design pattern is all about.
It lets us treat both types of objects uniformly so you have your individual objects the scalar objects
and you have the composite objects but they both share some interfaces that you can actually use.
Now in terms of enumeration of the objects if you want to get a listing of all the objects in both the
collection as well as the singular object where basically lists itself you have this idea of begin and
end pairs.
And in actual fact we're lucky in the way that C++ supports duck typing So essentially you if you have
begin and end pair implementation you appear as a collection or as a container whether or not you are
such in the first place.
And suddenly the trick here the trick of the composite design pattern is that a single object or a scalar
object can actually Maskerade itself as a collection.
And all you have to do is you have to implement begin and end and one of the examples that I've shown
is that you can put this pointer in the begin return function and you can stick the return this plus
one in the end function as a result.
You're going to appear as a container of just the single element and as a result the type that you're
working on which implements these members it can appear on the right hand side of a range based for
expression for example and that's certainly something that we've done in the in your on layer design
where we implemented this for both of the objects where any of the objects could be a scalar scalar
that's masquerading as a container.