Package legos

This package was created by Russell Zahniser (russell@zahniser.net) for use in teaching the basic concept of compound objects - objects that are built up of many other objects.

See:
          Description

Class Summary
Arm An Arm is a LegoPiece representing the arm of a lego person.
Body A Body is a LegoPiece representing the body of a lego person.
Hand A Hand is a LegoPiece representing the hand of a lego person.
Head A Head is a LegoPiece representing the head of a lego person.
Leg A Leg is a LegoPiece representing the leg of a lego person.
LegoPiece A LegoPiece represents some kind of object created by connecting together smaller pieces.
Legs A Legs is a LegoPiece representing the legs of a lego person.
 

Package legos Description

This package was created by Russell Zahniser (russell@zahniser.net) for use in teaching the basic concept of compound objects - objects that are built up of many other objects. So, for example, I can make a lego arm like this:

Arm arm = new Arm(new Hand(new Color(150, 0, 255)), new Color(0, 150, 0), canvas);

In this code I am actually creating four objects: an Arm, a Hand attached to it, and two Color objects specifying the colors of the hand and arm.

Somewhat later in a class, this package will be useful when you talk about drawing a diagram of a data structure and trying to retrieve parts of it. I could follow up the above code with this:

sint r = arm.getHand().getColor().getRed();

The more complex data structures available in this package challenge students to really understand what is being done in an expression like that, while providing visual cues to the structure of the data.

Later on, once you have studied loops and recursion, it can be fun to use this package to try to write more complex ObjectDraw programs. For example, one interesting challenge would be to try to create a "Paintball" game in which the part of the lego man that you click on is colored in some new color. Determining what was clicked requires iterating through each of the subunits of the man, and possibly recursively searching within each of those subunits. This is a fairly intuitive way to talk about recursive thinking. A more challenging assignment would be to create an interface in which the parts of the lego man can be assembled and disassembled.

You can learn more, or find similar labs, at www.zahniser.net/~russell/computer.

This package requires a modified version of the ObjectDraw library, also available from the above website.