You are on page 1of 4

Design Patterns Questions and Answers

Q 1 - Which of the following is true about design patterns?


A - Design patterns represent the best practices used by experienced object-
oriented software developers.
B - Design patterns are solutions to general problems that software developers
faced during software development.
C - Design patterns are obtained by trial and error by numerous software
developers over quite a substantial period of time.
D - All of the above.
Answer : D
Explanation
Design patterns represent the best practices used by experienced object-oriented
software developers. Design patterns are solutions to general problems that
software developers faced during software development. These solutions were
obtained by trial and error by numerous software developers over quite a
substantial period of time.

Q 2 - If we serialize a singleton object and deserialize it then the result object will
be same.
A - true
B - false
Answer : B
Explanation
false. Deserializing a serialized object will yield a different object.

Q 3 - Which of the following pattern is used when creation of object directly is


costly?
A - Bridge Pattern
B - Adapter Pattern
C - Prototype Pattern
D - Filter Pattern
Answer : A
Explanation
Prototype pattern is used when creation of object directly is costly.

Q 4 - Which of the following pattern provides a way to evaluate language grammar


or expression?
A - Proxy Pattern
B - Chain of Responsibility Pattern
C - Command Pattern
D - Interpreter Pattern
Answer : D
Explanation
Interpreter pattern provides a way to evaluate language grammar or expression.

Q 5 - Which of the following describes the Memento pattern correctly?


A - This pattern is used to get a way to access the elements of a collection object in
sequential manner without any need to know its underlying representation.
B - This pattern is used to reduce communication complexity between multiple
objects or classes.
C - This pattern is used to restore state of an object to a previous state.

-1-
D - This pattern is used when there is one-to-many relationship between objects
such as if one object is modified, its depenedent objects are to be notified
automatically.
Answer : C
Explanation
This pattern is used to restore state of an object to a previous state.

Q 6 - Which of the following describes the Visitor pattern correctly?


A - In this pattern, a visitor class is used which changes the executing algorithm of
an element class.
B - This pattern is used to separate application's concerns.
C - This pattern is used to decouple presentation tier and business tier.
D - This pattern is used in EJB persistence mechanism.
Answer : A
Explanation
In Visitor pattern, a visitor class is used which changes the executing algorithm of
an element class.

Q 7 - Which of the following is correct about Structural design patterns.


A - These design patterns are specifically concerned with communication between
objects.
B - These design patterns provide a way to create objects while hiding the creation
logic, rather than instantiating objects directly using new opreator.
C - These design patterns concern class and object composition. Concept of
inheritance is used to compose interfaces and define ways to compose objects to
obtain new functionalities.
D - None of the above.

Answer : C
Explanation
Structural design patterns concern class and object composition. Concept of
inheritance is used to compose interfaces and define ways to compose objects to
obtain new functionalities.

Q 8 - Which of the following describes the Prototype pattern correctly?


A - This pattern builds a complex object using simple objects and using a step by
step approach.
B - This pattern refers to creating duplicate object while keeping performance in
mind.
C - This pattern works as a bridge between two incompatible interfaces.
D - This pattern is used when we need to decouple an abstraction from its
implementation so that the two can vary independently.

Answer : B
Explanation
Prototype pattern refers to creating duplicate object while keeping performance in
mind.

-2-
Q 9 - Which of the following describes the Decorator pattern correctly?
A - This pattern allows a user to add new functionality to an existing object without
altering its structure.
B - This pattern is used where we need to treat a group of objects in similar way as
a single object.
C - This pattern hides the complexities of the system and provides an interface to
the client using which the client can access the system.
D - This pattern is primarily used to reduce the number of objects created and to
decrease memory footprint and increase performance.
Answer : A
Explanation
Decorator pattern allows a user to add new functionality to an existing object
without altering its structure.

Q 10 - Which of the following describes the Proxy pattern correctly?


A - In this pattern a class represents functionality of another class.
B - This pattern creates a chain of receiver objects for a request.
C - This pattern provides a way to evaluate language grammar or expression.
D - In this pattern a request is wrapped under an object as command and passed
to invoker object.
Answer : A
Explanation
In proxy pattern, a class represents functionality of another class. This type of
design pattern comes under structural pattern. In proxy pattern, we create object
having original object to interface its functionality to outer world.

Q 11 - Which of the following pattern is used to restore state of an object to a


previous state?
A - Iterator Pattern
B - Mediator Pattern
C - Memento Pattern
D - Observer Pattern

Answer : C
Explanation
Memento pattern is used to restore state of an object to a previous state.

Q 12 - In which of the following pattern, a class behavior or its algorithm can be


changed at run time?
A - State Pattern
B - Null Object Pattern
C - Strategy Pattern
D - Template Pattern

Answer : C
Explanation
In Strategy pattern, a class behavior or its algorithm can be changed at run time.

-3-
Q 13 - Which type of design patterns provide a way to create objects while hiding
the creation logic, rather than instantiating objects directly using new opreator?
A - Creational Design Patterns
B - Structural Design Patterns
C - Behavioral Design Pattern
D - J2EE Design Patterns

Answer : A
Explanation
Creational Design Patterns provide a way to create objects while hiding the creation
logic, rather than instantiating objects directly using new opreator.

-4-