A graphics library allows users to create simple shapes such as rectangles and circles as well as composite shapes such as cars and buildings. Of course a building might consist of roofs, floors, and entrances may also be composites. We can use the Composite Design Pattern to represent shape hierarchies:
This is a design model (instead of a domain model). It includes operations and other implementation details. Note that Shape and SimpleShape are abstract classes. This is because Shape declares the abstract draw method and SimpleShape inherits it. The position and size attributes represent the position and size of the shape on a virtual canvas. Note that they are protected, hence visible in all subclasses. Finally note the suggested implementation of draw in the CompositeShape class. It simply passes its graphical context parameter to each child's draw method.