________________________________ _________________________________ _________________________________
NAME ID SIGNATURE
Department of Electrical and Computer Engineering, McGill University
ECSE 321 - Introduction to Software Engineering
October 30, 2003, 11:35am-12:50pm
Prof. Radu Negulescu
• Do NOT open this booklet until the start and end times of the examination are written on the board
• Write your name, McGill student ID number, and signature on the cover of the answer booklet and at the
top of this page. Both booklets need to be handed in to the proctor at the end of the examination
• This examination is closed book, closed notes. No aids permitted
• Circle one answer only for each multiple-choice question in this examination booklet. Multiple-choice
questions are equally weighted. Each question has only one correct answer, which gets 2 marks. Wrong
answers get 0 marks or 1 mark (partial credit). No answers or multiple answers in a question get 0 marks
for that question
• Write your answers to the essay-type questions in the separate answer booklet provided. Draw a diagonal
line over each scratch sheet in the answer booklet; scratch sheets will not be marked
• This examination has 75 minutes only
SECTION I – MULTIPLE-CHOICE QUESTIONS
CIRCLE ONE ANSWER ONLY IN EACH QUESTION
Question 1. Which of the following coding conventions, principles or guidelines will NOT help in the
development or maintenance of Java code?
(a) Lines of code that are logically related should be placed near one another (principle of proximity)
(b) Each method of a class should have comments that clearly explain the relationships to every other method
of that class (one comment for every pair of methods in the class)
(c) Code layout should highlight the logical structure of the code (fundamental principle of code layout)
(d) Four spaces should be used as the unit of indentation (Java coding convention)
(e) Names should be problem-oriented
Answer: (b). Commenting pairs of methods is clearly excessive and it would create massive redundancies by
restating the preconditions of one method in all the callers. The other guidelines are used standard practice.
Question 2. Waived. (All examinees receive 2 marks.)
Question 3. Which of the following statements is true for flat statechart representations of typical software
systems? (By “flat statechart” we mean a statechart that does not use nesting or concurrency.)
(a) The number of states grows exponentially with the number of components in the system
(b) Each state explodes into several outgoing transitions
(c) A single transition might lead to several different states
(d) Large flat statecharts need to have more than one initial state
(e) None of the above
Answer: (a). It reflects an important phenomenon that limits what can be practically specified, by “flat” state
machines or other means. You have experienced some mild state explosion in Assignment 2 Question 1 (b).
Question 4. Which of the following requirements is most likely to occur in a properly stated SRS? (Assume the
SRS is “complete”, i.e., none of the requirements below needs to be “complete” all by itself.)
(a) “The system shall have a professional-looking user interface.”
(b) “Each button in the Formatting toolbar shall have a tooltip.”
(c) “The average time for refreshing the display shall be 4 seconds or less.”
(d) “The maximum time for registering a key press into memory shall be 0.1 seconds or less.”
(e) “The minimum time for refreshing the display shall be 0 seconds, if possible.”
Answer: (b). It meets all the criteria of good requirements, and it is particularly good because it specifies a UI
feature (“tooltips”) decoupled from the functionality features in the “Formatting toolbar” (regardless of the
number of buttons). Option (c) looks good but it is somewhat ambiguous, since it might be interpreted as a
“raster refresh rate” assumption rather than the “repainting graphical elements” obligation. It is important to
avoid multiple “standard” interpretations even if some of them don’t make much sense from a technical
Question 5. Waived. (All examinees receive 2 marks.)
FUHDWH QHZ (YHQW H
IRU HDFK UHJLVWHUHG /LVWHQHU O
(YHQW VRXUFH (YHQW OLVWHQHUV
Question 6. Consider the class diagram above, representing a basic event broadcast mechanism. Which of the
following statements is NOT true for this diagram?
(a) ConcreteSource objects can create new Event objects
(b) Listener objects can be added and removed at run time from a list maintained by a Source object
(c) The cast(Event) method of a ConcreteSource object calls the handle(Event) method of each registered
(d) ConcreteListener objects update the copyState fields of the Event objects
(e) Each Listener object can be registered with only one Source object
Answer: (d), because in this diagram event objects cannot be updated. Although in some frameworks we could
have listeners registered with multiple sources, Option (e) is not quite right in this diagram because the Source-
Listener association has multiplicity 1-*. This diagram is consistent with the basic (unsophisticated)
implementations of event passing mechanisms.
Question 7. Consider the software driver for a web camera, which captures the video image in real time and
makes it available over the Internet. Which of the following can NOT be an actor for the software driver?
(a) The Internet connection of the local computer
(b) The port used by the video camera
(c) The user
(d) Arnold Schwarzenegger
(e) All of the above are good actors for the web camera software driver
(Hint: do not confuse good actors with actor instances.)
Answer: (d). Arnie is not an actor because the software doesn’t need to be “aware” of him! Even if Arnie were to
purchase the software and use it as a user, Arnie can be at most an actor instance, but not an actor.
Question 8. The guideline of 7 +/– 2 submodules per level is considered optimal for the following reason:
(a) It reduces the memory requirements of the program
(b) It matches approximately the number of distinct concepts that can be handled simultaneously by an
(c) It increases the speed of the program
(d) It appeals to the subjective taste of the average developers
(e) None of the above
Answer: (b). Psychological/cognitive considerations are the basis for many guidelines for improving productivity
in software engineering. This particular guideline has nothing to do with program performance or memory
requirements, and there is nothing subjective about it.
Question 9. Which of the following can be a sequence of events involved in the MVC architecture, according to
the class diagram above:
(a) A Model object sends an event to a View object, which notifies a Controller object
(b) A View object sends an event to a Model object, which notifies a Controller object
(c) A Controller object sends an event to a Model object, which notifies several View objects
(d) All of the above
(e) None of the above
Answer: (c). This is the only one consistent with the associations in the diagram and the basic MVC architecture.
In some variations of MVC, controllers might “talk to” views, but, even there, views do not “talk back” to
The following two questions refer to the following insertion sort routine. (Array indices start at 1.)
routine insertionSort (A)
for j = 2 to length of array A
// INV: ...
key = A[j]
i = j – 1
while i 0 and A[i] key do
A[i + 1] = A[i]
i = i – 1
A[i + 1] = key
Question 10. Assume the insertionSort routine is used internally by a program. Which of the following
pre- and post-condition pairs is the most appropriate for insertionSort from a maintainability viewpoint?
(a) Pre: none; post: array is sorted
(b) Pre: array is not sorted; post: array is sorted
(c) Pre: array has at least one element; post: array is sorted
(d) Pre: array has at least two elements; post: array is sorted
(e) Pre: array reference is non-null; post: array is sorted
Answer: (e). As per tutorial, array references can (and should) be constrained by assertions. Option (a) is a close
call but Option (e) is more appropriate.
Question 11. Which of the following assertions is valid each time the program reaches the line “INV”?
(a) Items 1 through j are sorted
(b) Items 1 through j – 1 are sorted
(c) key equals A[j]
(d) i equals 0
(e) j equals 1
Answer: (b). All other options can be invalidated at some iteration of the loop.
Question 12. Keeping CRC cards to the size of 4x6 inches is considered important because:
(a) Software engineers prefer even numbers and inch measurement units
(b) This size allows just enough space to describe a class of optimal complexity in large script
(c) This size is conducive to optimal performance in implementing an object-oriented program
(d) All of the above
(e) None of the reasons above
Answer: (b). For this reason, some software developers actually feel very strongly about 4”X6” CRC cards.
Options (a) and (c) are ludicrous.
Question 13. Which of the following applies to the statement “If class X uses defensive programming in each
method, then good programming practice recommends that any subclass Y that inherits from X should also use
defensive programming in each method”
(a) Always true
(b) Always false
(c) It depends on whether or not the subclass is used at the boundary of the system
(d) It depends on whether the class invariant of Y is stronger than that of X or the same
(e) None of the above
Answer: (d). Option (a) is close but not quite right. If class X uses defensive programming in method M then
method M accepts any values for the parameters and the class fields. The Liskov Substitution Principle (LSP)
requires that class Y has method M that can also take any values for the parameters. However, the invariant of
class Y could be stronger, in which case method M can make certain assumptions regarding the values of the
class fields, without violating the LSP as long as proper encapsulation avoids direct access to the object’s fields.
The LSP is an excellent rule of thumb for using inheritance.
Question 14. You are developing a command-line user interface. Which of the following design patterns is the
most likely to make it easy to add new commands in later versions of the program?
Answer: (a). The Command pattern is used specifically for the purpose of making it easy to add new commands.
Question 15. Which of the following checks is LEAST likely to detect maintainability problems in an object-
(a) Tracing in the class diagram one scenario for each use case
(b) Tracing each design element to a functional requirement
(c) Checking that none of the design elements can be removed
(d) Checking for naming conflicts
(e) Using calibrated stubs to predict performance
Answer: (e). Calibrated stubs will detect performance problems but not maintainability problems. Tracing
scenarios in the class diagrams and checking for naming conflicts will detect inconsistencies; tracing design
elements and checking for removable design elements will detect redundancies. Inconsistency and redundancy
lead to poor maintainability.
SECTION II – ESSAY-TYPE QUESTIONS
WRITE YOUR ANSWERS IN THE ANSWER BOOKLET
Question 16. (Requirements, analysis)
You are developing ThumbsUp, a browser for the newest WebBerry, a popular wireless device that has a color
display and a mouse wheel, but no keyboard and no mouse. ThumbsUp has the following buttons only: “Back”,
“Forward”, “Page”, and “Exit”, in this sequence. Initially, ThumbsUp is in the “buttons” mode of operation, where
moving the wheel cycles through the buttons in the sequence above, and clicking the wheel activates the selected
button. As usual, buttons “Back” and “Forward” move back and forward through a list of recently visited web
pages, and button “Exit” exits the browser. Button “Page” makes the browser go into the “page” mode of
operation where moving the wheel cycles through the hyperlinks on the currently displayed web page and double-
clicking the wheel activates the selected hyperlink and loads and displays a new web page. Triple-clicking the
wheel goes back to the “buttons” mode. The default selections on entry to the “buttons” and “page” modes are the
“Back” button and the first hyperlink of the current page, respectively. The screen scrolls automatically in the
“page” mode to keep the current link within the viewable area. Each time ThumbsUp starts, it displays the home
page of WebBerryWorld.com, which has hyperlinks to several major web directories.
(a) Draw a use case diagram for ThumbsUp. Be sure to cover both stated and implied requirements and give
self-explaining names to the diagram elements. 
(b) Draw a sequence diagram for a scenario to visit 3 web pages (including the home page), then go back 1
web page, then go forward 1 web page to the last page visited. 
(c) Briefly describe how the requirements above may be changed to make them simpler, easier to implement,
and more useful to the user. Keep your description within 1/2 page maximum. Focus on the main
functional requirements only; do NOT discuss non-functional requirements, error conditions or secondary
flows. Hint: Try to make the user interaction with the browser more uniform. 
As discussed at the lectures, keeping requirements consistent provides better usability and learning curve for the
users AND a simpler system with more general modules and fewer special cases.
To avoid inconsistencies between the clicking rules for the buttons and the hyperlinks, hyperlinks should
be selected by a single click in the page mode, just like the buttons are selected in the buttons mode. There should
be some way of returning to the buttons mode, and the simplest way is by double clicking. (Frequent operations
should have simple commands.) Further, for consistency of clicking rules, we can do away with the “Page” button
and use a double click to go to the page mode. An option is to keep the “Page” button but also allow switching to
the page mode by double click.
Another possibility is to have a single loop of buttons and hyperlinks. However, that might make it more
difficult to navigate back to the buttons. We can use double clicking instead of triple clicking to go to the Back
button from any hyperlink.
Question 17. (Design)
You are developing WareStar, a software system for tracking warehoused computer subsystems. Subsystems can
be assembled on site from parts and from other warehoused subsystems. Subsystems can be removed from
WareStar by a user. When the number of subsystems of a certain type falls below a predetermined lower limit,
WareStar schedules assembly orders (in-house) or supply orders (to manufacturers) to replenish the inventory up
to a predetermined upper limit.
(a) Draw a class diagram for a high-level design model for WareStar. Hint: use the Composite pattern. 
recursively remove and
qty, onOrder, LL, UL
(b) Draw a statechart representing the lifecycle of a subsystem type maintained by WareStar, to clarify at least
the following issues: creation of the type, ordering from the manufacturer, reaching the lower control limit.
Make sure this statechart is consistent with the methods in the class diagram in Part (a). 
Low StocknewSubSys order On Order addQty Full Stock
(c) State any invariants on the data structures involved in Part (a). 
(LL = qty + onOrder = UL)
The “manufacturer” is the same for all SupplyOrder-s that are issued by the same SubSys
The components of a subsystem are always the same as on creation of that subsystem.