Minimalist Abstract State Pattern | 405
Now that you have an abstract Strategy design pattern where you can see the arrange-
ment of the different parts, an illustration where you can see all of the connections,
delegation and interactions in a single view will give you an overview of the process.
Figure 11-3 shows the connections between the different parts, all in one view.
In Figure 11-3, note how the call:
thinker.doStrategy( );
is delegated. Thethinkerinstance in theTestStrategyclass is typed as aContexttype
and instantiated as aConcreteContextobject. ThedoStrategy( )method is created in
theContextclass, and so that would be the first place to look, as the arrow from
doStrategy( )in theTestStrategyclass to thedoStrategy( )in theContextclass
shows.
However, in theContextclass thedoStrategy( )method has delegated the details to
thethink( )method, so we need to look elsewhere. In theConcreteStrategyclass, you
can see the details of thethink( )method. Because theConcreteContextstrategy is
instantiated in thethinkerinstance, it actually did the work, but sinceConcreteContext
is a subclass ofContext, the delegation is structured in theContext class.
Finally, we can trace the delegation framework back to the Strategyinterface.
Because the origin of thethink( )method is in theStrategyclass, we can see how it
is a delegate of theContext class.
Figure 11-3. Delegation connections