COMP 310
Fall 2017

Lec18:  Debugging in Eclipse and Visitors, revisited

Home  Info  Canvas   Java Resources  Eclipse Resources  Piazza

Debugging in Eclipse

Let's continue our discussion of the debugging features in Eclipse.


Visitors, revisited

Consider the conception of visitors mentioned at the end of last lecture.  


In Ballworld, we sent commands out, via the dispatcher, to untold masses of Ball objects.   Each ball invariantly took the command, an IBallCmd, and called the command's apply method.  This worked wonderfully and enabled us to get all the balls to do whatever we long as we wanted all the balls to do the same thing.  But what if there was more than one type of Ball, i.e. different subclasses of Ball, where we wanted one type of Ball to do one thing and another type of Ball to do something else?   Then what?

One could use a big if-else stack and laboriously check to see what type of ball the context was....   Why might this be a bad idea?

Are we taking advantage of the fact that every type of ball intrisically knows what kind of ball it is?

If we want each ball to be executing a different command, why not just send them just that?  What if we send a collection of commands to every ball?   Which command does any given ball execute?   Why its own, of course! 

How does the Visitor Design Pattern achieve this?


Decoupling Algorithms from Data Structures

Hosts -- provide intrinsic, atomic behaviors that form a "complete" set, where combinations of these behaviors span all possible things that can be done with the hosts.   Ideally, the behaviors are "orthoganol"  in that they are maximally decoupled from each other.

Visitors -- Are algortihms (in a very general sense) on the hosts that combine the intrinsic behaviors for a specific purpose.   Since they are physically separate from the hosts, the hosts are not coupled to specific algorithms or specific implementations of those algorithms.  But yet, the visitor pattern can always deliver the correct algorithm to the any given host.


© 2017 by Stephen Wong