Practice Final Exam - Advanced Object Oriented Design Programming | CS 635, Exams of Computer Science

Material Type: Exam; Class: ADV OBJ ORIENT DSGN PROG; Subject: Computer Science; University: San Diego State University; Term: Spring 2009;

Typology: Exams

Pre 2010

Uploaded on 03/28/2010

koofers-user-kge
koofers-user-kge 🇺🇸

1

(1)

9 documents

1 / 3

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
Name __________________________________________
The following might be names of patterns:! Abstract Class, Abstract Factory, Adapter, Bridge, Builder,
Chain of Responsibility, Collaborator, Command, Command Processor, Decorator, Façade, Factory
Method, Flyweight, Interpreter, Mediator, Memento, Observer, Prototype, Proxy, Singleton, Specifica-
tion, State, Strategy
The purpose of many of the design patterns is to make it easy to change some property of the
system.! What design pattern would you use to make it easy to change:
1. (3 points) The way a set of objects interact with each other
2. (3 points) The algorithm that an object uses
3. (3 points) The implementation of an abstraction
4. (3 points) The class of the object that a method returns.
5. (3 points) The kind and number of objects that react to changes in the object you are designing.
6. (3 points) The internal state of an object, but you want to be able to remember this state and then
later tell the object to go back to that state.
7. (3 points)! What design pattern should you think of first when you want to implement undo?
8. (3 points) What design pattern should you think of first when you want to implement one and only
one instance of a class?
9. (3 points) What design pattern should you think of when you want to hide how you construct a
complex object?
10.(3 points) What design pattern should you think of when when you have a class that you can not
modify conveniently?
Suppose you were designing the file system of an operating system.
5/14/09"CS 635 Final"Page 1 of 3
pf3

Partial preview of the text

Download Practice Final Exam - Advanced Object Oriented Design Programming | CS 635 and more Exams Computer Science in PDF only on Docsity!

Name __________________________________________ The following might be names of patterns: Abstract Class, Abstract Factory, Adapter, Bridge, Builder, Chain of Responsibility, Collaborator, Command, Command Processor, Decorator, Façade, Factory Method, Flyweight, Interpreter, Mediator, Memento, Observer, Prototype, Proxy, Singleton, Specifica- tion, State, Strategy The purpose of many of the design patterns is to make it easy to change some property of the system. What design pattern would you use to make it easy to change:

  1. (3 points) The way a set of objects interact with each other
  2. (3 points) The algorithm that an object uses
  3. (3 points) The implementation of an abstraction
  4. (3 points) The class of the object that a method returns.
  5. (3 points) The kind and number of objects that react to changes in the object you are designing.
  6. (3 points) The internal state of an object, but you want to be able to remember this state and then later tell the object to go back to that state.
  7. (3 points) What design pattern should you think of first when you want to implement undo?
  8. (3 points) What design pattern should you think of first when you want to implement one and only one instance of a class?
  9. (3 points) What design pattern should you think of when you want to hide how you construct a complex object?
  10. (3 points) What design pattern should you think of when when you have a class that you can not modify conveniently? Suppose you were designing the file system of an operating system.
  1. (3 points) You want to reuse the classes that access I/O devices from another project. However, those classes don't have the interface you want. One solution is to refactor them. Another solu- tion is to reuse them without changing them. Which design pattern would help you reuse the classes for the I/O devices in your operating system?
  2. (3 points) Your file system has many classes in it, but you want to hide them from the application programmers and present a simpler interface to them. What design pattern lets you hide the complexity of a subsystem like a file system?
  3. (3 points) Suppose your system should be able to implement many kinds of file systems. A Linux file system has Linux directories and Linux files, while a BSD file system and an NT file system have their own ways of representing directories and files. You want to be able to write reusable algorithms for the file system, but when these algorithms are creating directories and files, they will create them for Linux, BSD, or NT as appropriate. Which design pattern would help you cre- ate objects of the right class?
  4. (4 points) List two patterns that reduce tight coupling.
  5. (10 points) Decorator and Chain of Responsibility are similar because they both contain multiple nested classes. In other respects, they are quite different. Explain the differences between Deco- rator and Chain of Responsibility.
  6. (5 points) Observer/Strategy. Suppose you are building a simulation of a chemical factory. Your simulation contains a class called Container that represents a container that holds chemicals. Chemicals can flow into it and out of it. It has a method: addVolume(float amount) { volume = volume + amount; if (volume > maximum) overflow(); Iterator a = channels.iterator(); while (a.hasNext()) ((Channel) a.next()).calculateInput(); Iterator b = displays.iterator(); while (b.hasNext()) ((ContainerDisplay) b.next()).redisplay(); } There are a variety of "Channel" classes, each of which implements "calculateInput()", and a variety of "ContainerDisplay" classes, each of which implements "redisplay()". You decide that it would be better to use the Observer pattern and make Channels and ContainerDisplays be observers of the Container. Show the new version of addVolume()
  7. (5 points) How would the Channel and ContainerDisplay classes have to change?