Strategy Pattern and Delegation
Explore how delegation in C++ helps reduce tight coupling between classes by transferring operations from one object to another. Understand how delegation differs from inheritance and its role in implementing the strategy pattern to promote flexible and maintainable software design.
We'll cover the following...
Before moving on to discuss delegation, let’s understand the motivation behind it. Generally, after learning about inheritance, programmers make the mistake of using it very frequently.
Although inheritance is a very powerful concept, it increases the coupling between the base class and the derived class. For example, let’s say we have a base class named Sphere and a derived class named Football. Every time we make changes in the Sphere class, it will directly affect the derived class Football due to tight coupling. In some cases, it’s more desirable to avoid ...