Categories
Programming

Design patterns: Composition and Inheritance (Strategy pattern)

Instead of creating child classes, you create a new tree of classes and move some of the functionality away from the main tree.

You connect the trees via object creation, meaning some of the classes in one tree contrain objects with the other classes type.

The advantage is that the trees are more specialized in what they do, so functionality in one tree is independent from the other tree, and it just complement it.

The disadvantages is that now you are creating more classes, so it may be difficult to maintain and keep track of it.

Leave a Reply

Your email address will not be published. Required fields are marked *