Software Engineering Software Design Patterns 1 — Questions and Answers
Question 1: Which design pattern ensures a class has only one instance and provides a global point of access to it?
- Observer
- Singleton (Correct answer)
- Factory
- Decorator
Correct answer: Singleton
The Singleton pattern restricts instantiation of a class to a single object and provides a global access point.
Question 2: The Factory Method pattern is classified under which category of design patterns?
- Structural
- Behavioral
- Creational (Correct answer)
- Architectural
Correct answer: Creational
The Factory Method pattern is a Creational pattern that defines an interface for creating objects but lets subclasses decide which class to instantiate.
Question 3: Which pattern attaches additional responsibilities to an object dynamically without subclassing?
- Proxy
- Decorator (Correct answer)
- Adapter
- Bridge
Correct answer: Decorator
The Decorator pattern wraps an object to add new behaviors dynamically at runtime.
Question 4: The Observer pattern is best described as which type of relationship?
- One-to-one
- Many-to-many
- One-to-many (Correct answer)
- Many-to-one
Correct answer: One-to-many
The Observer pattern defines a one-to-many dependency so that when one object changes state, all its dependents are notified automatically.
Question 5: Which pattern provides a simplified interface to a complex subsystem?
- Facade (Correct answer)
- Composite
- Flyweight
- Chain of Responsibility
Correct answer: Facade
The Facade pattern provides a unified, simplified interface to a set of interfaces in a subsystem.
Question 6: Which design pattern is used to convert the interface of a class into another interface that clients expect?
- Bridge
- Proxy
- Adapter (Correct answer)
- Strategy
Correct answer: Adapter
The Adapter pattern acts as a bridge between two incompatible interfaces by wrapping an object.
Which design pattern ensures a class has only one instance and provides a global point of access to it?