CSCI 6448

Object Oriented Analysis and Design

Course Location
   ECCS 1B12

Course Time
   TR 12:30 PM - 01:45 PM

Topics
    What's New
    Schedule
    Bibliography
    Lectures
    Homeworks
    Related Materials
    Contact Information
    Evaluation Criteria

Homework 5: Design Patterns

Introduction

In class, we covered a variety of design patterns. In this assignment, you get a chance to implement three of them: Decorator, Observer, and Composite. 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 Observer pattern. Do not reuse the classes that implement the Observer pattern in the Java class library, I want you to implement the pattern yourself. Your program should create an object that has state that needs to be observed. It should attach at least two observers to this object and it should then change the state of the observed object twice. Each time the observers should indicate that they received the state change notification and retrieved and/or did something with the new state.
  2. Write a program that demonstrates the advantages of the Decorator pattern. Create an object with two operations that produce output when they are called. Create a decorator for that object that adds two additional operations that produce output when they are called. (For simplicity, you should have the operations write to standard out, e.g. do not try to implement a gui program that makes use of decorators graphically.) Instantiate an undecorated object and have your program call both operations. Then instantiate a decorator, use it to "decorate" the original object, then call all four operations provided by the decorator. The output of the original two operations should be decorated in some way. That is, it should be obvious that the original output of the undecorated object is being manipluated in some way by the decorator.
  3. Write a program that demonstrates the advantages of the Composite design pattern. The program should create a tree of objects consisting of both composite and leaf nodes (demonstrating that the composite has correctly implemented the child management functions, such as addChild(), removeChild(), getChild(), and getParent()). Make sure that your tree consists of at least three levels, e.g. a root node with multiple children, where at least one of those nodes is a composite node with children. The program should then call an operation on the root of the tree. All composite objects should delegate the operation to their children while all leaf nodes should perform the action. Note: you can optionally have the composite nodes do something in response to the operation but they should then delegate the operation to their children.

Evaluation

This homework assignment is worth 60 points, 20 points for each design pattern. Note: as discussed in lecture, I will be looking to see that your implementations match the structure of the design pattern as well as match the scenarios described above. 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, 1998-2003.
Last Updated: 4/13/03; 4:23 PM