CS 680
Spring, 2003
Ethan Bolker
Answers to Midsemester Exam
April 9, 2003

Maximum possible score: 50 points. Grade distribution:

	40-50	 1
	30-40	 6
	20-30	 4
	10-20	11 !

So the half the class that did really badly has company. To pass this course with the B you need you must do better on the final!


This exam is an experiment. The good news is that rather than asking a few highly specific questions to probe your ignorance, I've formulated general questions that give you the best chance to tell me things you've learned. The bad news is that you have a greater responsibility to use your time wisely, spending it on ideas that you think are really important.

Attached you will find a Java solution to the ticket system you have just completed in C++. It works - that is, it meets the specifications - but it's a terrible solution - full of bad smells. (I had to hold my nose to write it.)

  1. (15 points) Draw a UML sequence diagram illustrating what happens to make this output appear (assume the ticket in question is already in the queue and is next to be served).
      ts-login> operator
      Ticket 4
      submitted: Wed Apr 09 10:09:13 EDT 2003
      by: eb
      priority: high
      second high priority ticket - should be served second
      closed: Wed Apr 09 10:09:14 EDT 2003
    

    Answer: the important objects involved in producing this output are

    You should have a vertical column for each of these, with a column for the driver (main) at the left. The read the code, thinking carefully about which objects send messages to which other objects. For example, main sends an iterator() message to the queue. The queue then creates the Iterator i, and returns a reference to that object to main. Then main sends a next() message to the newly created Iterator. The iterator sends a message to the queue to get a reference to the next Ticket, which is returned to main.

    Most people missed most of this. You cannot pass this course with a B unless you can get UML sequence diagrams mostly right. Practice a lot between now and the final ...

  2. (15 points) Study the code. Jot down some notes to yourself about the parts of the design you don't like. Then discuss what you would do to refactor it. I will judge your answer in part on the significance of the issues you choose to address and the strategies you suggest, including the order in which you would plan to make changes.

    Answer.

    Most people identified many of the bad smells:

    That's "jotting down parts ... you don't like." It was worth about 5 points.

    Far fewer answered the question. The most important bad smell (when considering the need for refactoring) is the fact that there is essentially no object design here at all. The goal of the refactoring should be to redesign so as to use the model/view architecture. There should be a class to maintain the collection of tickets and a driver to send messages to that class to get work done. Only that class should know about the Ticket class. I allocated about 5 points for this part of the discussion.

    Finally, in order to refactor properly you need to follow Fowler's methodology. Only one person in the class said that he would start by capturing the output from this program, which works correctly, and then make small changes one at a time (he told me what they would be), testing each time to see that the output remained correct.

  3. (10 points) Discuss how the differences between C++ and Java influence the design and implementation of the ticket system.

    Answer. Most people made a correct list of how C++ and Java were different. Few people distinguished important differences (like memory management) from unimportant ones (where is i/o easier? who has a priority queue in the library?).

    Very few people even hinted at what I consider a correct answer, because very few people really read the question. It asks about design . In fact the difference between the languages has almost no effect on the design. There are some small differences in the implementation - how important or annoying those are depends more on which language you are familiar with than on anything intrinsic to the languages themselves.

  4. (10 points) Choose one short subject we studied this semester that you haven't yet discussed on this exam, invent a question about it and answer your question.

    Answer: Almost anything reasonable was acceptable. But I did judge your answer based in part on how important a topic you chose to discuss. Most people chose something about design patterns, which was a good idea. But just the singleton design pattern wasn't worth a full 10 points, particularly if you didn't get it right.