Unlimited Plugins, WordPress themes, videos & courses! Unlimited asset downloads! From $16.50/m
Lessons:24Length:2.4 hours
  • Overview
  • Transcript

3.16 Replace Type Code with Modules

This is another way of solving the problem of conditionals on a type property. Using modules to dissolve the conditional is similar in purpose to the polymorphism solution, but different in nature.

You should use modules to provide runtime flexibility in a process. If you need to change traits and/or behavior during a process in runtime, then use this pattern. If, however, you’re sure that the type for a class doesn’t change in runtime, then use the previous pattern.