Lessons:24Length:2.4 hours
• Overview
• Transcript

3.15 Replace Type Code with Polymorphism

Some of the hardest things to change are methods with more than one path. If you have a method that has an if condition, you immediately have more than one end result. That’s dangerous and leads to chaos later down the road. case statements are as bad or worse than if statements, so you ought to be really careful and watch for those path deviations.

In this lesson and the next two, you’ll deal with the special case of type properties in your classes. They are a sign of deviation in end results and are asking to be refactored. In this very lesson, you’ll learn how to use Polymorphism to accomplish the refactoring.