on GRAFFITI_WALL draw a RECTANGLE on ETCHASKETCH draw a RECTANGLE on GRAFFITI_WALL draw a QUADRILATERAL on ETCHASKETCH draw a QUADRILATERAL on GRAFFITI_WALL draw a PARALLELOGRAM on ETCHASKETCH draw a PARALLELOGRAM on GRAFFITI_WALL draw a POLYGON on ETCHASKETCH draw a POLYGON on GRAFFITI_WALL draw a RECTANGLE on ETCHASKETCH draw a RECTANGLE on GRAFFITI_WALL Setup Before looking at SHAPE or SURFACE, we need to examine the high level decoupled use of our double-dispatch. Visitor pattern The visitor pattern works by way of a visitor object visiting the elements of a data structure (e.g. list, tree and so on) polymorphically, applying some action (call or agent) against the polymorphic element objects in the visited target structure. In our example below, we make a list of polymorphic SHAPE objects, visiting each of them with a polymorphic SURFACE, asking the SHAPE to be drawn on the SURFACE. make -- Print shapes on surfaces. local l_shapes: ARRAYED_LIST [SHAPE] l_surfaces: ARRAYED_LIST [SURFACE] do create l_shapes.make (6) l_shapes.extend (create {POLYGON}.make_with_color ("red")) l_shapes.extend (create {RECTANGLE}.make_with_color ("grey")) l_shapes.extend (create {QUADRILATERAL}.make_with_color ("green")) l_shapes.extend (create {PARALLELOGRAM}.make_with_color ("blue")) l_shapes.extend (create {POLYGON}.make_with_color ("yellow")) l_shapes.extend (create {RECTANGLE}.make_with_color ("purple")) create l_surfaces.make (2) l_surfaces.extend (create {ETCHASKETCH}.make) l_surfaces.extend (create {GRAFFITI_WALL}.make) across l_shapes as ic_shapes loop across l_surfaces as ic_surfaces loop ic_surfaces.item.drawing_agent (ic_shapes.item.drawing_data_agent) end end end We start by creating a collection of SHAPE and SURFACE objects. We then iterate over one of the lists (SHAPE), allowing elements of the other (SURFACE) to visit each of them in turn. In the example code above, SURFACE objects are visiting SHAPE objects. The code makes a polymorphic call on {SURFACE}.draw indirectly by way of the `drawing_agent', which is the first call (dispatch) of the double-dispatch pattern. It passes an indirect and polymorphic agent (`drawing_data_agent'), allowing our visitor code to only know about two things: What is the drawing agent of the surface (e.g. al_surface.drawing_agent on line #21)? What is the drawing data agent of the shape (e.g. al_shape.drawing_data_agent on line #21)? Because both SURFACE and SHAPE define their own agents, our visitor code is freed from having to know what is the appropriate call to make, polymorphically or otherwise. This level of indirection and decoupling is simply not achievable in other common languages like C, C++ and Java except through either some form of reflection or feature overloading with signature matching. SURFACE Within the polymorphic call to {SURFACE}.draw is the call to an agent, which becomes the second polymorphic call or