Monday, October 27, 2014

OOAD Quiz 3

good site for pattern reference
http://www.oodesign.com/  
most of the answers are here:
http://www.numeroreal.com.br/down_manuais/JAVA/Gang-of-four-java-design-patterns-gof-exam.pdf

1.The term "Delegation" is most closer to which of the following GRASP patterns
Select one:
a. Expert
b. Creator
c. Low Cohesion
d. Controller {correct}

http://people.cs.kuleuven.be/~roel.wuyts/OASS1-0910/OASS1-0910-2.pdf

2.Which GOF design pattern is applied in the code snippet below?
public class PrintSpooler {
    private static final PrintSpooler INSTANCE = new PrintSpooler();
    private PrintSpooler() {}
    public static PrintSpooler getInstance() {
        return INSTANCE;
    }
}
Select one:
a. PrintSpooler
b. Spooler
c. Singleton {correct}
d. Factory

3.Which design pattern is used in the Java InputStream and OutputStream hierarchies?
Select one:
a. Adapter design pattern
b. Decorator design pattern {correct}
c. Composite design pattern
d. Singleton design pattern

4.Which of the following are participants in the Composite design pattern?
Select one or more:
a. Component {correct}
b. Compound
c. Leaf {correct}
d. Connection

5.What is the difference between an adapter and a decorator? Choose all that apply.
Select one or more:
a. The adapter adds no functionalities to the adaptee class, whereas the Decorator extends the functionality of the object {correct}
b. The adapter is a creational pattern, whereas the decorator is a structural design pattern
c. Both introduce a level of indirection between a client class and a class it uses {correct}

6.Which GRASP pattern asnwers the question "What object should have the responsibility, when you do not want to violate High Cohesion and Low Coupling, or other goals, but solutions offered by Expert are not appropriate?"
Select one:
a. Pure Fabrication {correct}
b. Indirection
c. Creator
d. Polymorphism

7.We should avoid software that is weakly cohesive because
Select one:
a. It makes software harder to maintain;
b. It makes software harder to understand;
c. It makes software harder to test;
d. It makes software harder to reuse;
e. All of the above; {correct}
f. None of the above.

@@@:source wikipedia   http://en.wikipedia.org/wiki/Cohesion_(computer_science)

8.In the Publish-Subscribe messaging model, the subscribers register themselves in a topic and are notified when new messages arrive to the topic. Which pattern does most describe this model?
Select one:
a. Adapter
b. Notifier
c. Observer {correct}
d. Factory

9.Which pattern is known to encapsulate a request as an object?
Select one:
a. Factory
b. Command Pattern {correct}
c. Observer Pattern
d. Strategy Pattern

10.An instructor wants to schedule an exam for which he/she wants that a notification is sent to all the registered students automatically. Which design pattern is most suitable for him.
Select one:
a. Composite
b. Observer {correct}
c. Decorator
d. Iterator


11.Which of the following are participants in the GOF Adapter design pattern? Choose all that apply.
Select one or more:
a. Adapter {correct}
b. Adaptee {correct}
c. Bridge
d. Target interface {correct}

12.When would you use the GOF Decorator design pattern?
Select one: 
a. to translates an existing class interface into a compatible target interface
b. to assign more functionality to an object without sub-classing it {correct}
c. to decouple an abstraction from its implementation so that the two can vary independently
d. to nest layers of decorators to add more functionality

13.When would you use the GOF Composite design pattern?
Select one:
a. to decouple an abstraction from its implementation so that the two can vary independently
b. to translates an existing class interface into a compatible target interface
c. to arrange object hierarchies such that the client code can access both the individual objects and 
    compositions in a uniform manner {correct}
d. to improve the system overall performance

14.Which are considered forces to select a Strategy Pattern? Choose all that apply.
Select one or more:
a. A client needs to use a family of related objects  {correct}
b. A change to an object requires changing other objects   {correct}
c. A client needs to choose from multiple algorithms {correct}
d. Multiple classes are the same but differ only in their behaviors {correct}

15.Which design pattern you would you use to control the creation of an object based on a established interface, while allowing the concrete implementation to determine the subclass to construct.
Select one:
a. Singleton
b. Composite
c. Decorator
d. Factory {correct}

16.A pattern that is intended to provide a means to define a family of algorithms and encapsulate each one as an object for interchangeable use:
Select one:
a. Strategy Pattern {correct}
b. Factory Pattern
c. Observer Pattern
d. Adapter Pattern

17.Which GRASP pattern is suitbale to handle alternatives based on type?
Select one:
a. Indirection
b. Pure Fabrication
c. Polymorphism {correct}
d. Creator

18.A concrete class must have
Select one:
a. No program code for any of its methods
b. Program code for all of its methods {correct}
c. Program code for some of its methods
d. No program code for some of its methods

19.It is also known as Wrapper, it is used when subclassing is not possible or practical to add functionality and it is used to add functionality at runtime. This pattern is
Select one:
a. Compostite
b. Decorator {correct}
c. Adapter
d. Observer

20.Which design pattern you would you use to limit the class instantiation to one object?
Select one:
a. Factory
b. Singleton {correct}
c. Observer
d. Adapter

No comments:

Post a Comment