Design patterns – Composite

Hello guys,

I’m back with the Composite pattern.

I’ll just say a few words about it and the rest can be seen on the github page.
First of all, I’ve updated the page so each design pattern is in a different project, and you can find in there all the information you need.
I’ve also added the simplest UML, for each of the pattern explained so far, so please revisit them if interested.


  • It has many use cases, but it is usually used to implement tree nodes. It contains the following classes:
  1. class BaseClass
    – contains functionality used for both containers and leafs (eg data)
    – contains a public virtual function
  2. class ContainerClass : public BaseClass
    – contains a vector/array/container of objects of type BaseClass, can add / remove elements from the container, can also iterate through them and call the virtual function from BaseClass
  3. class LeafClass : public BaseClass
    – contains only the virtual function overriden

The full code can be found at the following link:

You may also like...

Leave a Reply