The exam will be 75 minutes. You may bring your refactoring textbook but no handwritten notes will be allowed.
Question #1 (35 %)
Object-oriented programming has been around since 1967 (Simula-67). Over the many years that people have been developing software using OO techniques, many "best practices" have been developed. This question involves one of those best practices.
There are different types of relationships which can exist between classes:
When the developer identifies that a relationship exists between two classes, he/she must determine which type of relationship is the best to use for this case. The best practice that has developed over time is the following:
Favor association over inheritance
Essentially, there are times when a designer/developer could define an inheritance relationship between two classes or an association relationship between those classes. If the developer cannot judge which is the best to use in this specific case, the best practice suggests that the association relationship is the better default choice.
Based on the course material, evaluate this best practice. Does the course material support it or not? Do you agree that this is a good default position to take when designing relationships between classes? Are there cases where using this best practice could cause more damage than good?
For your answer, provide at least 1 example of a design to which this best practice could be applied. To make it easy for your marker to evaluate your design, please show a UML diagram of both designs (ie. the one using inheritance and the one using association)
Note: keep your UML diagram simple. I don't want you to spend a lot of time on it. I just want to know what the key elements of your design are for evaluating your answer to this question.
Question #2 (35 %)
You are currently teaching a 1st year programming course and you are using an object oriented language as part of the course. You have just completed the section on polymorphism and a student comes up to you after class with a question. Her question is as follows:
"I understand how polymorphism works. You, like, define a function, errr, method in a super class and then, like, override it in a subclass. I also kinda get how polymorphism can work like an if statement but what I just don't get is why I would ever use polymorphism. Why don't I just, like, use an if statement when I need to make these kinds of decisions? It seems like a lot of extra work for nothing."
As the prof for this course, you are aware that software design isn't really taught until second year so your student has very limited understanding of design issues. Based on her question, what is it that she doesn't understand and what is an appropriate answer to her question? Very important: You want the student to have a better understanding of polymorphism and its uses, but you do not want to confuse the student further. Are there details that you could give her that you might choose to leave out because of her (currently limited) understanding of software design?
Question #3 (30%)
While participating in a discussion on UseNet about Refactoring, you come across the following post:
"Who would use something as stupid as refactoring? After all, why use a system whereby you assume that everything you do first is all wrong so you gotta go back and do it all over again? It seems like a big make work project to me."
Your goal is to change the opinion of this poster. You have debated with him before and you know that he responds well to fact-based arguments. However, those facts must be supported as he disregards assertions made by other posters which do not have any support. What is your response to this poster?
Note: Although you may want to flame the poster, doing so will lose marks :-)