Suppose you have to design an application for drawing 2D geo
Suppose you have to design an application for drawing 2D geometric shapes.
Some shapes are complex and may contain one or more shapes, basic or complex. For instance, a House shape includes 3 Rectangle (basic) shapes, a Chimney shape, and an Ellipse (basic) shape. The Chimney is a complex shape and includes 4 Line shapes. A complex shape behaves like a basic shape but also allows one to add/remove basic shapes to/from it.
What design pattern must be applied to these shape concepts ?
Strategy
Observer
Decorator
Composite
I think the asnwer is composite, since this pattern groups components into a whole.
| Strategy |
| Observer |
| Decorator |
| Composite I think the asnwer is composite, since this pattern groups components into a whole. |
Solution
For the above design we can use Composite design pattern, the composite design is the structured design pattern so that your answer is correct and the composite is a tree structure of simple and composite objects.
