Previous Lecture Lecture 11 Next Lecture

Lecture 11, Wed 11/02

Factory Design Pattern, instanceof as a code smell, Parsing

H14 problem, Q4:

See: https://github.com/UCSB-CS56-F16/Head-First-Design-Patterns/blob/master/src/edu/ucsb/cs56/pconrad/hfdp/CS56_F16_H14_Q4.java

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.