CSCI 6448

Object-Oriented Analysis and Design

Course Location
   ECCS 1B28

Course Time
   Tuesday and Thursday
    9:30 AM - 10:45 AM

Topics
   What's New (Home)
   Class Schedule
   Lectures
   Homeworks
   Useful Links

Homework 5: Design Patterns

Introduction

In class, we covered a variety of design patterns. In this assignment, you get a chance to implement two of them: Decorator and State. You may use any Object-Oriented programming language to implement the patterns: C++, Java, Smalltalk, etc. Note: only implement the minimal amount of code you need to demonstrate the design pattern (e.g. these should be relatively short programs).

Instructions

  1. Write a program that demonstrates the advantages of the State design pattern. The program should create an object that has at least three states. This object should have one operation that returns different output depending on its current state. It should also have an operation that asks the object to change state. This operation should in turn ask the current state object to select the next state. Your program should instantiate the object, and call the state-dependent operation three times, each time calling the change state operation in between. As a result, your program should produce output that shows that the object is indeed changing state, since the same operation will produce different output depending on the current state.
  2. Write a program that demonstrates the advantages of the Decorator pattern. Create an object with several operations that produce output when they are called. Create a decorator for that object that adds additional operations that produce output when they are called. Instantiate an undecorated object and have your program call each operation. Then instantiate a decorator, use it to "decorate" the original object, then call all of the operations that you did before plus the operations of the decorator.

Evaluation

This homework assignment is worth 45 points. Please turn in the source code and the output produced by running your program. If you submit electronically, combine your source code files and output into a single archive.

This homework can be turned in via hard copy, fax, or submitted electronically. Please remember that acceptable formats for electronic submission are ASCII, postscript, and PDF. Send ASCII submissions in the body of an e-mail message (not as an attachment). Send postscript/PDF submissions as an attachment to an e-mail message. If you send postscript, be sure to embed any special fonts that you may use directly into the postscript font. (Most printer drivers provide an option to allow you to embed fonts.) Make sure that your e-mail message is clearly marked (as discussed in lecture 1) and that this same information appears in the attached document.

Any questions?

Send questions to <kena@cs.colorado.edu>. Answers to common questions will be discussed in class and/or posted to the class website.


© Ken Anderson, 2001.
Last Updated: 4/25/01; 3:12:39 PM