Previous Lecture Lecture 11 Next Lecture

Lecture 11, Wed 11/02

Factory Design Pattern, instanceof as a code smell, Parsing

H14 problem, Q4:


Try running this and you’ll see the problem.

What is a code smell?

So, why do we have instanceof all in the lab06 code?

Great question. To be honest, we shouldn’t. Kyle Dewey already wrote a version of this code that does a refactoring using the Visitor Pattern (see the Appendix of HFDP, pages 634-635). However, trying to understand the visitor pattern at the same time that you are already dealing with understanding tokenizing, parsing and interpreting ASTs seemed a little too much to take on at once.

We’ll come back and try to understand how to refactor the evaluator code for lab06 that code out once we understand the whole process of parsing a bit more.