0% found this document useful (0 votes)
27 views3 pages

Module 12.F Pre-Class Worksheet

Uploaded by

Rutherford paul
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
27 views3 pages

Module 12.F Pre-Class Worksheet

Uploaded by

Rutherford paul
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

COMP 215: Intro to Program Design

Dr. Rebecca Schreib

Name: [Your name]

The following worksheet is based on Module 12.F Pre-Class (Design Patterns II). As
usual, you should create a personal copy of this worksheet, fill it out, and submit it to
Canvas prior to the deadline.

1. Fill in the following chart for the three design patterns discussed in the Design
Patterns II video.

In what situation(s) What are the key structural


Pattern
is it a good design? feature(s)?

Observer Pattern [Your answer] [Your answer]

Strategy Pattern [Your answer] [Your answer]

Visitor Pattern [Your answer] [Your answer]

2. What is the difference between overriding and overloading a method in Java?


You should address the differences in definitions as well as the differences in
terms of how Java determines which version of a method ultimately gets called.
[Your answer]

3. What is double dispatch, and why is it necessary in the visitor pattern? You
should address the need for the accept() method as well as the need to
re-define the accept() method within each concrete subclass of IVisitable.
[Your answer]

4. The strategy and visitor patterns are similar in that they both decouple an
algorithm from the class on which it operates. What is the key difference between
them? (Hint: it has to do with the nature of the object that the algorithm operates
on, and how the nature of that object influences the algorithm itself!)
[Your answer]

5. The following problem appeared on a test in a past iteration of the course.


You’re designing an application that will be used by a travel agency to help
clients plan and book trips. A client’s overall journey can consist of many legs,
where a leg is defined as a journey from a single source to a single destination.
So far, you’ve defined an IStoreTravelLogistics interface and two classes that
implement IStoreTravelLogistics: Ticket and Itinerary. A Ticket represents
travel on a ticketed mode of transportation for a single leg of the journey. An
Itinerary is composed of arbitrarily many IStoreTravelLogistics objects. In
completing your application, you’d like to make use of some of the following
design patterns:

1. The Singleton Pattern


2. The Factory Pattern
3. The Builder Pattern
4. The Composite Pattern
5. The Adapter Pattern
6. The Observer Pattern
7. The Strategy Pattern
8. The Visitor Pattern

The left column of the following table describes several tasks that you’re trying to
accomplish. Fill in each cell in the right column with a number between 1–8
corresponding to the design pattern from the list above that is the best fit for the
task described in that row. Determine the best fit based on the goal of the task,
the existing infrastructure, and the principles taught in COMP 215.

You want to streamline the process of creating a complete [Your


Itinerary, including all of the IStoreTravelLogistics objects that it answer]
contains. However, you don’t want to clutter the Itinerary class
itself with the code for creating all of the individual
IStoreTravelLogistics objects comprising the journey.

You want to help the client find the optimal mode of transportation for [Your
a single leg of their journey. You have a database that rates each answer]
possible combination of (mode of transportation, source, destination)
according to a variety of different metrics such as speed and
comfort. You want the client to be able to choose a single metric to
maximize, and you will then search your database for the optimal
mode of transportation based on that metric.

You want to design a user interface for browsing available tickets for [Your
a given leg of the client’s journey. You want this user interface to answer]
always stay up-to-date with the latest information about available
tickets. Information about ticket availability can also be found in the
database. Each time the information in the database changes, you
want the user interface to automatically refresh in order to reflect the
most up-to-date ticket availability.

The legs that comprise a client’s journey may be non-contiguous, [Your


i.e., the client may spend some time at a location before traveling to answer]
the next one. After creating an Itinerary for the client, you want to
implement an algorithm for computing the total time that will be
spent traveling on a ticketed mode of transportation during the entire
itinerary, taking into consideration all of the IStoreTravelLogistics
objects that comprise the itinerary and excluding the time spent at
each location. Moreover, you want to decouple this algorithm from
the Itinerary class itself.

6. Which of the above questions are you unsure about the answers to? List the
question numbers here so that you remember to discuss them with your group
during class. If you don’t have any questions, you can answer this question with
“N/A” (not applicable).
[Your answer]

7. What other questions do you have related to today’s material that you want to
discuss with your group / the staff during class? If you don’t have any questions,
you can answer this question with “N/A” (not applicable).
[Your answer]

You might also like