CSE 115 - Fall 2006 - Banner
   CSE 115 - Fall 2006 - Introduction to Computer Science for Majors I
CSE 115 - Fall 2006 - Left Navigation CSE 115 - Fall 2006 - Lab 6

Lab 6

Introduction

This week's lab is a continuation of last week's lab in that it extends an idea introduced in that lab. The idea is that of a general composite object, an object which allows us to group two objects into a single unit. In order to do this, we make use of the association relationship that we learned about in class.


Objectives

The high-level objectives of this lab are to have you,
  • declare instance variables
  • call methods on objects using an instance variable
  • express the realization relationship in code (i.e. you will write a class which implements a given interface)
  • express the association relationship in code (i.e. you will write a class which knows another class)
  • use green to create and edit a class diagram
The following are the new concepts covered in this lab:
  • association
  • design patterns in general, but the composite design pattern more specifically

Assignment Specifications

Background and motivation

As we said in lab 5, grouping is an important idea. In lab 5 we saw how to make define classes to help us group instances of specific classes. However, in doing so repeatedly we seem to be missing an important generalization: no matter which classes' instances we are composing, the composing class has the same basic layout. You probably felt when you were defining the MixUpThree and MixUpFive classes for lab 5 that you were doing essentially the same thing over and over again.

Wouldn't it be great to be able to separate out the idea of putting together multiple objects into one from the specific objects being composed? It turns out we can! This is a such a common task in software development that there is a standard "best practices" solution available. It is called the composite design pattern. In this lab you will implement this design pattern, and build the same functionality you did in part 2 of lab 5 with much less coding effort.

Design patterns

The composite design pattern is just one example of a design pattern. Design patterns are "best practices" solutions to recurring software development problems. Design patterns are mined from existing code, written by software developers, and therefore represent examples of high-quality designs that practicing software developers actually use.

The idea of design patterns actually come from the field of architecture. The architect Christopher Alexander's work on patterns in architecture inspired the so-called "Gang of Four", Erich Gamma, Richard Helm, Ralph Johnson and John Vlissides (who sadly passed away recently), to catalog a set of design patterns in a book, called Design Patterns: Elements of Reusable Object-Oriented Software. This book catalogs several design patterns; since then (it was published in 1995) many design patterns have been catalogued.

In this course we introduce you to several very useful design patterns. The first, as you know, is the Composite Pattern. Throughout the rest of the semester you will be introduced to a selection of fundamental patterns which will help you understand the design of pieces of the Java class libraries (such as the graphical library).

What you need to do

Step 1

Remember, as we have said in the last several labs, it is important to build your code in small stages until you get to the finished product. You must also define the Applet so that it uses a Lab6System.

To build your composite class, you need to implement the design shown in the following UML diagram:

Notice that not only does the CompositeShape know two IMovingShapes, it is itself an IMovingShape. Thinking about it for a bit, this makes some amount of sense: the composite shape can be used as a shape. This is what happened in lab 5: the MixUpThree and MixUpFive But the MixUpThree and MixUpFive classes didn't hold IMovingShapes. But herein lies the great flexibility of the composite, because this allows the composite to hold any IMovingShape, including a CompositeShape!

Step 2

Now build a CompositeShape consisting of three IMovingShapes (include one lab5lib.Oval, one lab5lib.Triangle and one lab5lib.Rectangle). Note that to do this you need only instantiate classes that already exist - you must not define any new classes.

Hook this CompositeShape up appropriately to the buttons. Test your implementation of the composite by checking that the buttons affect all the shapes of the composite.

Step 3

Now build a CompositeShape consisting of five IMovingShapes (include at least one instance each of the classes lab5lib.Oval, lab5lib.Triangle and lab5lib.Rectangle). Beyond this, the exact mix of shapes is not important.

Hook this CompositeShape up appropriately to the buttons. Test your implementation of the composite by checking that the buttons affect all the shapes of the composite.

Step 4

You must use Green to produce a UML class diagram of the lab6 package and all of its related classes. Be sure to save this file as Lab6.dia in your workspace, and be sure to include this file when you export your solution to hand in..

Helpful Hints

Read through the entire lab before you start working, so that you know what to expect. Make sure you save your work often, and keep track of what you are expected to submit.

Do not be afraid to refer to earlier labs to recall what things mean or what commands are available for you to use.


Reading

Make sure you have read to the end of chapter 4 before coming to lab. Also make sure you have reviewed your lecture notes.


Lab set-up tasks
(There are no special directions if you are working at home: follow these same directions.)

At your lab session your teaching assistant will briefly discuss how to carry out each of the set-up tasks below. She or he will also be available to answer questions you might have. Before you start work on the lab itself, you must carry out each of the following set-up tasks. Your teaching assistant will guide you through this process. Refer back to other lab assignments if you do not remember how to complete these tasks.

Step 1: Log in

Step 2: Start Eclipse

Step 3: Check out Lab6 project from LabSkeletons repository

Step 4: Do the required lab work (instructions above)

Step 5: When finished, export your project and submit it (instructions below)


What you hand in

When you are finished, you need to export your solution from the Eclipse environment so that you can submit it. You need to follow the same steps as you did for disconnecting from the repository in Lab 2. If you are not sure how to do this, please refer back to those instructions. This time, you should name your Jar file Lab6.jar.

Then you can submit the Lab6.jar file using the electronic submission program. If you do not remember how to use the the submission program, refer back to earlier labs.


Due dates

You have one week from the meeting of your lab to submit your solution.  The due dates are summarized in the table below. You are always welcome to submit early. If you submit more than once, the later submission will simply overwrite the previous one.

To check that your lab was submitted, you can always refer back to the Submit Inspector on the Resources page of the website. After you have entered your user name, your submissions will be shown. Clicking on the name of a file that is a zip file will show you the contents of the zip file so you can verify that you indeed zipped up all the correct files.

Date of lab Due date for electronic submission
Wednesday, October 11 Tuesday, October 24
Thursday, October 12 Wednesday, October 25
Tuesday, October 17 Monday, October 23
Friday, October 20 Thursday, October 26

 

CSE 115 - Fall 2006 - Footer

 

 
Last modified: Mon Oct 9 18:24:37 2006