Lessons:24Length:2.4 hours
  • Overview
  • Transcript

3.17 Replace Type with State/Strategy

This pattern dissolves a type code conditional in a different level from the other two. Sometimes, a type code implies a complex execution in which you’d rather separate those them into their own classes. They are probably asking for that since the code you’re trying to run is not of the first class’ responsibility, anyway.

In this lesson, you learn how to use a strategy class to distinguish unique code that depends on a type code. The strategy/state you instantiate when evaluating the type determines the parent class’ unique behavior.