In a Singleton class, the constructor is typically declared as:
public
private
protected
static
In the Adapter Pattern, what is the 'Adaptee'?
The class that implements the Adapter Pattern.
The client code that interacts with the adapter.
The interface that the client expects to use.
The class that needs to be adapted to a different interface.
Which of these scenarios would be a suitable use case for the Decorator Pattern?
Implementing a logging system that can be added to different parts of an application.
Representing a family tree with complex relationships between members.
Creating different types of vehicles with varying features.
Managing the state of an object throughout its lifecycle.
How does the Decorator Pattern achieve the dynamic addition of responsibilities?
By modifying the source code of the decorated object at runtime.
By composing objects, where decorators wrap the component and delegate to it.
By using reflection to alter the behavior of methods during execution.
By using inheritance to create subclasses with extended functionality.
In the context of the Factory Method pattern, what does the 'factory method' typically return?
An abstract interface or base class type.
An instance of a specific concrete class.
A primitive data type, such as an integer or a string.
A configuration object used to customize object creation.
How does the Command Pattern achieve decoupling?
By introducing an intermediary object (the Command) between the invoker and the receiver.
By directly connecting the object making the request with the object fulfilling it.
By relying on a central registry to map requests to their handlers.
By using inheritance to create specialized request handlers.
In the context of the Strategy Pattern, what does a 'Context' object typically do?
It implements the actual algorithms defined by the Strategy interface.
It acts as a factory for creating Strategy objects.
It defines the interface for all Concrete Strategies.
It maintains a reference to a Strategy object and delegates work to it.
Which of the following is a key difference between the Factory Method and Simple Factory patterns?
Simple Factory is better suited for complex object creation hierarchies.
Factory Method uses inheritance, while Simple Factory relies on a single factory class.
Simple Factory promotes extensibility, while Factory Method is less flexible.
Factory Method handles object creation centrally, whereas Simple Factory distributes it.
What is the primary intent of the Command Pattern?
To ensure a class has only one instance, and provide a global point of access to it.
To provide a way to access the elements of an aggregate object sequentially without exposing its underlying representation.
To define a family of algorithms, encapsulate each one, and make them interchangeable.
To encapsulate a request as an object, thereby allowing for the parameterization of clients with different requests.
How does the Strategy Pattern promote the Open/Closed Principle?
It prevents modification of existing strategies, ensuring their integrity.
It promotes code reuse by allowing strategies to be shared across multiple contexts.
It reduces the need for inheritance, making the codebase more flexible.
It allows adding new strategies without modifying the existing Context class.