Design Patterns MCQ

If you’re new to the world of software design patterns, this quiz is a great way to test your knowledge and understanding of the subject. Design patterns offer reusable solutions to commonly occurring problems in software design. Let’s see how well you know the basics.

1. Which design pattern is primarily concerned with creating objects?

a) Command
b) Strategy
c) Factory
d) State

Answer:

c) Factory

Explanation:

The Factory pattern deals with object creation, allowing an object to be created without specifying its concrete class.

2. The Singleton pattern ensures:

a) A class has only one instance
b) A class delegates its tasks
c) A class changes its behavior at runtime
d) A class is split into several smaller classes

Answer:

a) A class has only one instance

Explanation:

Singleton ensures that a particular class has only one instance and provides a way to access that instance from any point in the app.

3. The Observer pattern is used when:

a) One object changes state, all registered observers are notified and updated automatically.
b) You want to add responsibilities to an object dynamically.
c) You want to ensure only one instance of an object exists.
d) Multiple classes need to be combined into one unified interface.

Answer:

a) One object changes state, all registered observers are notified and updated automatically.

Explanation:

The Observer pattern defines a one-to-many dependency where multiple observer objects are listening to one subject object.

4. Which pattern can be used to create a clone of an existing object?

a) Factory
b) Builder
c) Prototype
d) Adapter

Answer:

c) Prototype

Explanation:

The Prototype pattern is used when creating an instance of a class from an existing instance (or prototype) by cloning.

5. Which design pattern helps you create complex objects step-by-step?

a) Builder
b) Factory
c) Prototype
d) Chain of Responsibility

Answer:

a) Builder

Explanation:

The Builder pattern helps in building a complex object step by step.

6. Which design pattern turns a request into a stand-alone object?

a) Command
b) Observer
c) Strategy
d) Mediator

Answer:

a) Command

Explanation:

The Command pattern encapsulates a request as an object, thereby allowing for parameterization of clients with queues, requests, and operations.

7. Which design pattern promotes the loose coupling of a system?

a) Adapter
b) Observer
c) Chain of Responsibility
d) Singleton

Answer:

b) Observer

Explanation:

The Observer pattern defines a one-to-many dependency between objects so that when one object changes state, all its dependents are notified and updated automatically. This promotes loose coupling.

8. Which design pattern encapsulates an algorithm inside a class?

a) Strategy
b) State
c) Mediator
d) Command

Answer:

a) Strategy

Explanation:

The Strategy pattern defines a family of algorithms, encapsulates each one, and makes them interchangeable. Strategy lets the algorithm vary independently from clients that use it.

9. Which design pattern is used for creating an object clone?

a) Factory
b) Adapter
c) Prototype
d) Builder

Answer:

c) Prototype

Explanation:

The Prototype pattern creates a new object by copying an existing object, known as the “prototype.”

10. What does the Factory Method pattern do?

a) Adds responsibilities to objects dynamically
b) Defines a family of algorithms
c) Defines an interface for creating an object
d) Encapsulates a request as an object

Answer:

c) Defines an interface for creating an object

Explanation:

The Factory Method pattern defines an interface for creating an object, but allows subclasses to alter the type of objects that will be created.

11. Which design pattern provides a way to access the elements of an aggregate object?

a) Composite
b) Iterator
c) Mediator
d) Command

Answer:

b) Iterator

Explanation:

The Iterator pattern provides a way to access the elements of an aggregate object without exposing its underlying representation.

12. What is the main purpose of the Chain of Responsibility pattern?

a) Decouple sender and receiver
b) Clone objects
c) Pass a request along a chain
d) Build complex objects

Answer:

c) Pass a request along a chain

Explanation:

The Chain of Responsibility pattern passes the request along a chain of handlers, allowing multiple objects to handle the request.

13. Which design pattern is best for sharing state-sensitive resources?

a) Flyweight
b) Composite
c) Bridge
d) Factory

Answer:

a) Flyweight

Explanation:

The Flyweight pattern minimizes memory usage or computational expenses by sharing as much as possible with related objects.

14. What does the Decorator pattern do?

a) Adds new functionality to an object without altering its structure
b) Creates a clone of an object
c) Defines a new interface for an object
d) Manages object states

Answer:

a) Adds new functionality to an object without altering its structure

Explanation:

The Decorator pattern dynamically adds new functionality to an object without altering its structure.

15. Which pattern is used to structure subsystems and decouple them from the client?

a) Proxy
b) Adapter
c) Façade
d) Observer

Answer:

c) Façade

Explanation:

The Façade pattern provides a simplified interface to a group of subsystems, decoupling clients from the complex internals.

16. Which design pattern adds new functionality to an object without altering its structure?

a) State
b) Decorator
c) Composite
d) Command

Answer:

b) Decorator

Explanation:

The Decorator pattern dynamically adds new functionality to an object without changing its structure.

17. What does the Bridge pattern aim to achieve?

a) Decouple abstraction from implementation
b) Clone objects
c) Hide complex subsystems
d) Pass a request along a chain

Answer:

a) Decouple abstraction from implementation

Explanation:

The Bridge pattern aims to decouple an abstraction from its implementation so that the two can vary independently.

18. What does the Proxy pattern do?

a) Provides a surrogate for another object
b) Adds functionality to an object
c) Turns a request into a stand-alone object
d) Promotes loose coupling

Answer:

a) Provides a surrogate for another object

Explanation:

The Proxy pattern provides a surrogate or placeholder for another object to control access to it.

19. Which design pattern composes objects into tree structures to represent part-whole hierarchies?

a) Composite
b) Iterator
c) Proxy
d) State

Answer:

a) Composite

Explanation:

The Composite pattern composes objects into tree structures to represent part-whole hierarchies, allowing clients to treat individual objects and compositions uniformly.

20. Which pattern provides a way to traverse a collection without exposing its underlying structure?

a) Composite
b) Iterator
c) Proxy
d) Mediator

Answer:

b) Iterator

Explanation:

The Iterator pattern provides a way to traverse a collection without exposing its underlying structure.


Whether you’re new to design patterns or brushing up on your knowledge, quizzes like this can help identify areas of strength and those that might need further study. Keep practicing and deepening your understanding of these essential software design tools!

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top