Module hw06

Class VisitorDemoModel

java.lang.Object
visitorDemoExercises.basicVisitorDemo.model.VisitorDemoModel

public class VisitorDemoModel extends Object
The main model object for the Visitor Demo system.
Author:
swong
  • Field Details

    • logger

      private ILogger logger
      logger to use
    • view

      private IViewAdapter view
      The adapter out to the view
    • paintCmd

      private Consumer<Graphics> paintCmd
      The installed painting command instance. Initially set to a no-op cmd.
    • loader

      private IObjectLoader<IVisitor> loader
      The dynamic class loader for the IVisitors.
  • Constructor Details

    • VisitorDemoModel

      public VisitorDemoModel(IViewAdapter view)
      The constructor for the class
      Parameters:
      view - the adapter to the view
  • Method Details

    • getHosts

      public IHost[] getHosts()
      Get an array of the available host types, i.e. IHost subclasses.
      Returns:
      An array of IHost objects
    • run

      public Object run(IHost host, String visitorClassname)
      Return the results of having the given host object execute the visitor corresponding to the given class name. A reference to this model object is given as the visitor's input parameter.
      Parameters:
      host - An IHost object
      visitorClassname - The name of the visitor class, without the leading "visitors.impl."
      Returns:
      The results of the visitor execution on the given host.
    • loadVisitor

      private IVisitor loadVisitor(String classname)
      Utility method to load a visitor given its classname, without the leading "visitors.impl.".
      Parameters:
      classname - the visitor's classname
      Returns:
      An IVisitor object
    • paint

      public void paint(Graphics g)
      Paint on the given Graphics object using the current IPaintCmd object in the model.
      Parameters:
      g - The Graphics context on which to draw.