MSH Logo - our design strategy

Thu, Jan 26, 2006 2-minute read

As I mentioned last time, this series of articles will introduce you to some of the features of Monad’s hosting model.  Before we get into the details of hosting Monad, though, we need to first lay out our conceptual framework.

Our application is a simple WinForms control.  It displays a small triangle (of Logo fame,) and users control movement of the turtle through a small set of commands.  The turtle supports the following:

  • Pen Up
  • Pen Down
  • Forward [steps]
  • Backward [steps]
  • Left [degrees]
  • Right [degrees]
  • Hide
  • Show
  • Some facility for looping
  • Some facility for functions / routines

We will model this set of commands as closely as we can, giving the Turtle class responsibility for everything but looping and routines.

Also, the turtle leaves a trace on the screen whenever it moves while the pen is down.  The .Net Framework already gives us a class to handle the responsibility of being a canvas – via the Graphics class. 

That leaves a question – how should we handle interaction between the turtle and the screen? How will we draw the actual lines?  To solve that, we’ll provide the Turtle with a reference to the Graphics class.  As the turtle moves, it will also be in charge of leaving a trail of ink.

Another option would be to place drawing responsibility with a controller class.  Before every command, it could determine the turtle’s position.  After every command, it could again determine the turtle’s position.  If the turtle’s pen is down, it could draw a line between the two.  However, that approach sounds like a case of Feature Envy.  The controller spends nearly all of its time muddling with properties of the turtle class.  In that case, the turtle should just do the work itself.

So, that’s our general approach.  We’ve designed a sturdy object model, and are ready to go implement it.  We’ll continue next time by integrating it into a GUI.

[Edit: Monad has now been renamed to Windows PowerShell. This script or discussion may require slight adjustments before it applies directly to newer builds.]