Docsity

Design Patterns Midterm Exam Questions and Answers - Prof. R. E. Whitney, Exams of Computer Science

Toggle sidebar
bg1
Name __________________________________________
Answer all 10 questions. Answer essay questions as briefly as possible.
The following might be names of patterns:! Abstract Class, Abstract Factory, Adapter,
Application Controller, Bridge, Builder, Chain of Responsibility, Collaborator, Command,
Composite, Decorator, Façade, Factory Method, Flyweight, Interpreter, Iterator, Master-
Slave, Mediator, Memento, Null Object, Observer, Prototype, Proxy, Singleton,
Specification, State, Strategy, Template Method, Visitor.
1. Suppose you were designing the file system of an operating system.
A. The file system has tree-structured directories.! Which design pattern is indicated
by the tree structured directories?
B. 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 create objects
of the right class?
2. 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:
A. The algorithm that an object uses
B. The number of objects that need to be notified when an object changes state
C. Adding operations to classes without changing the class
2/16/10"CS 635 Midterm Exam"Page 1 of 2
pf2

Partial preview of the text

Download Design Patterns Midterm Exam Questions and Answers - Prof. R. E. Whitney and more Exams Computer Science in PDF only on Docsity!

Name __________________________________________ Answer all 10 questions. Answer essay questions as briefly as possible. The following might be names of patterns: Abstract Class, Abstract Factory, Adapter, Application Controller, Bridge, Builder, Chain of Responsibility, Collaborator, Command, Composite, Decorator, Façade, Factory Method, Flyweight, Interpreter, Iterator, Master- Slave, Mediator, Memento, Null Object, Observer, Prototype, Proxy, Singleton, Specification, State, Strategy, Template Method, Visitor.

  1. Suppose you were designing the file system of an operating system. A. The file system has tree-structured directories. Which design pattern is indicated by the tree structured directories? B. 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 create objects of the right class?
  2. 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: A. The algorithm that an object uses B. The number of objects that need to be notified when an object changes state C. Adding operations to classes without changing the class 2/16/10 CS 635 Midterm Exam Page 1 of 2
  1. What is a Big Ball of Mud? What forces lead to a Big Ball of Mud?
  2. The design patterns text claims it uses two main design principles. Select one pattern that uses both principles. Show how it uses both.
  3. Explain Coupling and Cohesion. What is the difference between Internal Object Coupling and object cohesion?
  4. Explain one of the following types of cohesion: Logical, Temporal, Procedural, Communication, Sequential. Give an example.
  5. Show how to implement the singleton. Give one situation in Java where the singleton pattern can fail to be a singleton.
  6. In object-oriented programming programers are told to avoid if (case) statements and replace them with polymorphism. A. What is wrong with using if or case statements? B. List one design pattern that replaces if (case) statements? Explain.
  7. The visiter pattern uses double dispatch. Most programming languages do not support double dispatch directly. What is double dispatch? How does the visitor pattern implement it in languages that do not support double dispatch.
  8. Object-oriented programming utilizes a number of design principles. Some design patterns violate one or more design principles. List one such design pattern, the design principle it violates and explain how the design pattern violates the design principle. 2/16/10 CS 635 Midterm Exam Page 2 of 2