Download CSE 403 Software Engineering Midterm Exam Solutions and more Exercises Programming Languages in PDF only on Docsity!
University of Washington
CSE 403 Software Engineering
Spring 2011
Midterm exam
Friday, May 6, 2011
Name: Solutions
CSE Net ID (username):
UW Net ID (username):
This exam is closed book, closed notes. You have 50 minutes to complete it. It contains 22 questions and 8 pages (including this one), totaling 100 points. Before you start, please check your copy to make sure it is complete. Turn in all pages, together, when you are finished. Write your initials on the top of ALL pages. Please write neatly; we cannot give credit for what we cannot read. Good luck!
Page Max Score
Total 100
Initials: Solutions 1 TRUE/FALSE
1 True/False
(2 points each) Circle the correct answer. T is true, F is false.
- T / F Showing your customer a mockup of the UI is one good way to get feedback while gathering requirements.
- T / F For an announcement within your team, email is more appropriate than making the an- nouncement during a meeting. Meetings should be reserved for discussions — two-way communication — rather than announce- ments which are one-way communication.
- T / F When evaluating a UI via paper prototyping, the materials should have a crisp, professional appearance, to aid in obtaining good feedback.
- T / F Cohesion refers to elements in the same module, whereas coupling refers to elements in different modules.
- T / F Suppose you are able to find the true revealing sub-domains for a software system, and you design unit tests for it accordingly. Later, if you change your implementation, it is also necessary to update your tests so that they still cover the revealing sub-domains, which may have changed. A revealing subdomain corresponds to a sequence of choices made by the program, so it is a fea- ture of the implementation rather than the specification. The existing unit tests would need to be supplemented to consider the revealing subdomains of the new implementation. (In the handed-out version of the exam, this question was ambiguous, so we gave credit for both answers.)
- T / F When designing tests, if partitions are chosen perfectly, there is no point to testing boundary values near the edges of the partition.
- T / F Glass-box tests designed for one implementation are valid to use when testing another im- plementation.
- T / F In an implementation of the singleton pattern, there is no constructor. There is a constructor, but it is private.
Initials: Solutions 3 SHORT ANSWER
3 Short answer
- (4 points) The later a problem is found in the software development process, the harder it is to fix. Explain why, in one sentence.
- Other work may be built on a flawed foundation, so correcting the original problem may require significant rework.
- If the software has already been widely distributed, it might be expensive to get a fix out.
- The developer(s) involved might have forgotten the context surrounding the bug, so it’ll be harder to fix.
- The bug might be located in any existing code, and there’s more to search through as time passes.
- (4 points) Give an example of a design pattern whose use is obvious from a class diagram but not from a sequence diagram. (Don’t choose one that is built into (some) programming languages, such as inheritance.) Explain why, in 1 sentence. Composite: the members of a class are of a type that allows similar operations (perhaps they im- plement an interface in common with the container class). Observer: especially easy if there’s an 〈observes〉 notation on an arrow. For many patterns it’s possible to argue either way (and we were looking for your argument, not just a name). A common pitfall here was conflating class and object diagrams.
- (4 points) Give an example of a design pattern whose use is obvious from a sequence diagram but not from a class diagram. (Don’t choose one that is built into (some) programming languages, such as iteration.) Explain why, in 1 sentence. Factory: an actor creates an object in response to a call, and the caller subsequently sends messages to the newly created object. Decorator: every message to the decorator object is followed by a call to the object it decorates.
- (5 points) Event-driven programming is appropriate for user interfaces and user interaction.
- Give a different example domain. Networking. Disk access. Operating system interrupts. Web servers. A thermostat (takes action when the temperature is too high or low). Any user interface is a wrong answer: it is the same domain, not a different one.
- In one phrase or sentence, state the characteristics of domains where event-driven programming is appropriate. Unpredictable delays. Other acceptable answers are: Unpredictable events. Real-time device control. Asynchronous control. “Non-sequential” is not an adequate answer by itself; it is not a necessary condition. “User input” is too restrictive. A surprising number of people gave characteristics that were violated by either user inter- faces or their answer to the other part of the question; this inconsistency could have been an indication to them that their answer was not correct (usually, it was too specific).
Initials: Solutions 3 SHORT ANSWER
- (5 points) Consider two components A and B. Two software engineers, Laurel and Hardy, measure the dependences between A and B. Laurel uses these dependences when computing cohesion, and Hardy uses these dependences when computing coupling. Is this possible, if both engineers are performing a sensible and useful computation? In 1–2 sentences, explain why or why not. Yes. Laurel is considering a larger module C that contains both A and B as implementation details. Hardy is considering the implementation of C, and thinking of A and B as modules.
- (6 points) In 1 sentence each, give two distinct reasons that you should not commit compiled code (such as .o or .class files) to a version control repository.
- Merge conflicts cannot be resolved. Another way of saying the same thing is that binary files are not diffable (by the standard text-based diff algorithms).
- Repetition of information in source and binary forms violates the DRY (don’t repeat yourself) principle.
- Binary files such as .o files are architecture-dependent and may not be useful to others.
- Binary files may contain information such as timestamps that is guaranteed to create a conflict even if generated from the same source code by others.
- Bloat in the VCS because differences are huge.
- Timestamps might not be preserved.
- If there is a check-in without compiling, then they can be inconsistent with the source code.
- (8 points) It is cheaper and faster to fix known bugs before you write new code. Why? In one phrase or sentence each, give three reasons. Give reasons that are as different from one another as possible.
- You are familiar with the code now. A related reason is that the bug will be harder to find and fix later.
- Later code may depend on this code. A related reason is that a bug may reveal a fundamental problem.
- Leaving all bugs to the end will make it harder to understand and keep to the schedule, because it’s hard to predict how long bug fixing will take.
- An overfull bug database is demoralizing and is likely to be ignored.
- You will be able to add tests for the bug once it’s been fixed to avoid future issues.
- Avoid feature creep.
Initials: Solutions 3 SHORT ANSWER
- (10 points) Recall that the interning pattern guarantees that any two objects with the same abstract value are represented by just one concrete object. Answer each part in one sentence.
(a) Give a usage pattern (or its characteristics) in which the interning pattern uses less memory, compared to not using it, and explain why. A compiler symbol table, in which most symbols are used multiple times, so eliminating du- plication saves memory. (b) Give a usage pattern (or its characteristics) in which the interning pattern uses more memory, compared to not using it, and explain why. A situation in which most objects have different values, so the overhead of the hash table used by the interning implementation outweighs the reduction in memory used by duplicate objects. (c) Give a usage pattern (or its characteristics) in which the interning pattern uses less time, com- pared to not using it, and explain why. Ignore effects that are really due to memory use, such as faster allocation. Interning makes comparisons complete faster (the equals method always first checks object equality), so if there are many comparisons, the speedup outweighs the time cost of interning, which is a search for an equal object. (d) Give a usage pattern (or its characteristics) in which the interning pattern uses more time, com- pared to not using it, and explain why. Ignore effects that are really due to memory use, such as thrashing. If few equality checks are performed, then the speedup does not outweigh the time cost of performing interning. The main goal of interning is to save memory, so interning can be worthwhile even if it slows down the program.
Initials: Solutions 3 SHORT ANSWER
- (11 points) Explain the difference between a self-call, a synchronous callback, and an asynchronous callback. Give a concrete example of each. Draw a sequence diagram for each, and explicitly mark the self-call or callback in each (one marked call in each). Several students answered the question as if it asked about calls rather than callbacks, and dis- cussed issues such as blocking until a response is received. This is orthogonal to the notion of a callback. Also, some diagrams omitted return arrows, which is crucial to understanding the overall order of events, especially when distinguishing varieties of callbacks. Self-call: Explanation: A method call on this , or to the current module. It can be to any method — it doesn’t have to be recursive. Recursion is an example, not a definition. Example: Any call to a helper procedure. Sequence diagram:
Synchronous callback: Explanation: A client calls an external library that cannot do its work without delegating some work back to the client; the second call is the callback. Once the callback returns, the library eventually returns control to the client. Example: A map’s call to hashCode. Sequence diagram:
Asynchronous callback: Explanation: A client indicates to a library its interest in some event. The original call, that registers interest, returns immediately. At some indeterminate future time(s), the library calls the client to inform it that the event occurred. Example: Event listeners and futures are the two main uses for asynchronous callbacks. Sequence diagram: