This set of Advanced Java Multiple Choice Questions & Answers (MCQs) on “Design Patterns”.
1. Which of the below is not a valid design pattern? Answer: d 2. Which of the below author is not a part of GOF (Gang of Four)? Answer: b 3. Which of the below is not a valid classification of design pattern? Answer: d 4. Which design pattern provides a single class which provides simplified methods required by client and delegates call to those methods? Answer: c 5. Which design pattern ensures that only one object of particular class gets created? Answer: a 6. Which design pattern suggests multiple classes through which request is passed and multiple but only relevant classes carry out operations on the request? Answer: b 7. Which design pattern represents a way to access all the objects in a collection? Answer: a 8. What does MVC pattern stands for? Answer: b 9. Is design pattern a logical concept. Answer: a 10. Which design pattern works on data and action taken based on data provided? Answer: a
a) Singleton
b) Factory
c) Command
d) Java
Clarification: Design pattern is a general repeatable solution to a commonly occurring problem in software design. There are various patterns available for use in day to day coding problems.
a) Erich Gamma
b) Gang Pattern
c) Richard Helm
d) Ralph Johnson
Clarification: Four authors named Richard Helm, Erich Gamma, Ralph Johnson and John Vlissides published a book on design patterns. This book initiated the concept of Design Pattern in Software development. They are known as Gang of Four (GOF).
a) Creational patterns
b) Structural patterns
c) Behavioural patterns
d) Java patterns
Clarification: Java patterns is not a valid classification of design patterns. The correct one is J2EE patterns.
a) Adapter pattern
b) Builder pattern
c) Facade pattern
d) Prototype pattern
Clarification: Facade pattern hides the complexities of the system and provides an interface to the client using which client can access the system.
a) Singleton pattern
b) Filter pattern
c) State pattern
d) Bridge pattern
Clarification: Singleton pattern involves a single class which is responsible to create an object while making sure that only one object gets created. This class provides a way to access the only object which can be accessed directly without need to instantiate another object of the same class.
a) Singleton pattern
b) Chain of responsibility pattern
c) State pattern
d) Bridge pattern
Clarification: Chain of responsibility pattern creates a chain of receiver objects for a particular request. The sender and receiver of a request are decoupled based on the type of request. This pattern is one of the behavioral patterns.
a) Iterator pattern
b) Facade pattern
c) Builder pattern
d) Bridge pattern
Clarification: Iterator pattern represents a way to access the elements of a collection object in sequential manner without the need to know its underlying representation.
a) Mock View Control
b) Model view Controller
c) Mock View Class
d) Model View Class
Clarification: Model represents an object or JAVA POJO carrying data.View represents the visualization of the data that model contains. The controller acts on both model and view. It is usually used in web development.
a) True
b) False
Clarification: Design pattern is a logical concept. Various classes and frameworks are provided to enable users to implement these design patterns.
a) Command pattern
b) Singleton pattern
c) MVC pattern
d) Facade pattern
Clarification: Command pattern is a data driven design pattern. It is a behavioral pattern. A request is wrapped under an object as command and passed to the invoker object. The invoker object looks for the appropriate object which can handle this command and passes this command to the corresponding object which executes the command.