CS 151 Lecture 13

Cover page image

Cay S. Horstmann

Lab

Put your answers into lab13/report.txt. Turn in your diagrams as PNG files or photos.

Sequence Diagrams

  1. Look at Section 2.9 of your textbook. In the code in ch02/mail, exactly which line of code corresponds to Figure 2-11?
  2. If the first object rectangle were to use the full description, what would it be?
  3. Suppose you have a call x.f(y), and x is of type C and y of type P. Draw a sequence diagram with as much information as you can. Which parts can you not fill in? Why? Which part of the information can't you use? Why? The book points out one of the limitations. Which?
  4. Consider the call
    x = new A(y);
    where again x is of type C and y is of type P. Draw a sequence diagram with as much information as you can. What is different about this diagram? Where in the book was that difference mentioned?

Lambdas

The Exam Question

  1. Look at my implementation of homework 5. Look at line 26 of IntSeqTest.java. Start with three objects: the unit test object, seq1, and seq2. What are their types? For an anonymous class that implements an interface, use ? implements InterfaceName.
  2. Where in the book does it say to use ? implements ...?
  3. Draw just the arrow for the call
    seq1.alternate(seq2);
    Now look at Section 2.9 and carefully check whether you did it right. How can you tell?
  4. Look inside my alternate method. What kind of arrow do you need to draw what it does?
  5. Add that to your sequence diagram. You should now have four objects.
  6. Move on to line 27 of IntSeqTest.java. We don't really care about the call to assertEquals since we aren't trying to learn how JUnit works. What call do we care about? Draw one arrow for that call.
  7. Where is the implementation for that next method?
  8. In that implementation, what methods are called? On what object? Draw the arrows.
  9. Now repeat the same for line 28.
  10. Have a look at the complete diagram. What central question about alternate does it answer?

Discussion