Archive

Archive for the ‘QUIZ-6’ Category

Quiz 6 Solutions

December 12, 2011 Leave a comment

You can download solutions from: BILKENT-CS319-DesignPatternsQuiz6-111212(x)

True / False Questions (each 1 pt.)
1. A class diagram is a dynamic view of the classes in a system. (T / F) (False)
2. There are built-in classes in Java SE API such as java.util.Observable. (T / F) (True)
3. Subject and Observers are tightly coupled. (T / F) (False)

Fill in the Blanks Questions (each 2 pt.)
1. Add / remove listener methods in AbstractButton (JButton’s superclass) are an example of ________ pattern. (Observer)
2. Find the matching pattern for the following scenario: A top level component like a Frame or a Panel, contains other components like menus, text panes, scrollbars and buttons. You tell the top level component to display, and count on that component to display all its parts. ______ (Composite)
3. The java.io package is largely based on _______. (Decorator)
4. The _________ design pattern lets you attach responsibilities to objects at runtime. (Decorator)
5. _________ provides a unified interface to a set of interfaces in a subsystem. (Facade)
6. _________ defines a family of algorithms, encapsulates each one, and makes them interchangeable. (Strategy)
7. The usage area of this pattern is as follows: Thread pools, Objects that handle preferences and registry settings, objects used for logging, objects that act as device drivers. Find the pattern. _______ (Singleton)
Classic Questions (each 3 pt.)
1. Why is synchronized keyword used in this code example?
public class Singleton {
private static Singleton uniqueInstance;
private Singleton( ) { }
public static synchronized Singleton getInstance( ) {
if(uniqueInstance == null)
uniqueInstance = new singleton();
return uniqueInstance;
}
}
To solve multithreading problem. By adding synchronized to getInstance( ), we force every thread to wait its turn before it can enter the method. That is, no two threads may enter the method at the same time.

Advertisements
Categories: QUIZ-6

Quiz 6 Questions

December 12, 2011 Leave a comment

You can download questions from here: BILKENT-CS319-DesignPatternsQuiz6-111212

True / False Questions (each 1 pt.)
1. A class diagram is a dynamic view of the classes in a system. (T / F)
2. There are built-in classes in Java SE API such as java.util.Observable. (T / F)
3. Subject and Observers are tightly coupled. (T / F)

Fill in the Blanks Questions (each 2 pt.)
1. Add / remove listener methods in AbstractButton (JButton’s superclass) are an example of ________ pattern.
2. Find the matching pattern for the following scenario: A top level component like a Frame or a Panel, contains other components like menus, text panes, scrollbars and buttons. You tell the top level component to display, and count on that component to display all its parts. ______
3. The java.io package is largely based on _______.
4. The _________ design pattern lets you attach responsibilities to objects at runtime.
5. _________ provides a unified interface to a set of interfaces in a subsystem.
6. _________ defines a family of algorithms, encapsulates each one, and makes them interchangeable.
7. The usage area of this pattern is as follows: Thread pools, Objects that handle preferences and registry settings, objects used for logging, objects that act as device drivers. Find the pattern. _______

Classic Questions (each 3 pt.)
1. Why is synchronized keyword used in this code example?
public class Singleton {
private static Singleton uniqueInstance;
private Singleton( ) { }
public static synchronized Singleton getInstance( ) {
if(uniqueInstance == null)
uniqueInstance = new singleton();
return uniqueInstance;
}
}

 

Categories: QUIZ-6