Homework 2

This assignment is worth up to two extra credit points. Most students will receive only one point; only the highest quality answers will receive two points.

The figure below contains two class diagrams showing different ways to arrange three classes: Shape, Rectangle, and Square. Describe what each diagram is asserting about the classes, i.e. what is it that you know about these classes based on the semantics of the UML notation. How are the semantics of these two diagrams similar and how are they different?

Shapes with Inheritance Shapes with Delegation

Now, imagine in the diagram on the left that the Rectangle class defines two attributes: width and height and defines getter and setter methods for these attributes in the standard way. However, the Square class cannot directly reuse all four of these methods. Why not? Does this have any implication on using inheritance between Rectangle and Square? Put another way, can using inheritance between these two classes cause any problems?

Given your answer to the previous questions, discuss how the diagram on the right might address the problems and/or implications that you described.

This assignment is due by 11:55 PM on Tuesday, September 16th. Please upload a text file or PDF file to the moodle that contains the answers to the questions above.

Any questions? Send them to Prof. Anderson. Recall that you must not work with other students on this assignment. To remind you of this, please include the following pledge at the top of your assignment:

“On my honor as a University of Colorado at Boulder student, I have neither given nor received unauthorized assistance on this work.”

Kenneth M. Anderson, 2008