Which object-oriented principle does the Factory Method pattern primarily promote?
Dependency Inversion Principle
Open/Closed Principle
Single Responsibility Principle
Liskov Substitution Principle
What is the primary intent of the Observer pattern?
To ensure a class has only one instance.
To define a family of algorithms, encapsulate each one, and make them interchangeable.
To provide a way to access the elements of an aggregate object sequentially without exposing its underlying representation.
To define a one-to-many dependency between objects so that when one object changes state, all its dependents are notified and updated automatically.
What is the main difference between Object Adapter and Class Adapter?
Object Adapter uses inheritance, while Class Adapter uses composition.
There is no difference, both are implemented the same way.
Class Adapter uses inheritance, while Object Adapter uses composition.
Object Adapter is suitable for adapting concrete classes, while Class Adapter is for interfaces.
Which of these scenarios best illustrates a use case for the Singleton pattern?
Managing a database connection pool for an application.
Implementing a sorting algorithm for a list of numbers.
Creating multiple user accounts for a website.
Displaying different product variations on an e-commerce site.
What is the primary intent of the Command Pattern?
To encapsulate a request as an object, thereby allowing for the parameterization of clients with different requests.
To ensure a class has only one instance, and provide a global point of access to it.
In a Singleton class, the constructor is typically declared as:
protected
static
private
public
How does the Decorator Pattern differ from traditional inheritance for extending functionality?
Inheritance allows for dynamic extension at runtime, while Decorator does not.
Decorator provides more flexibility by allowing the combination of multiple functionalities at runtime.
Inheritance is generally preferred over Decorator due to its simplicity.
Decorator modifies the original class, while inheritance creates new subclasses.
What is a key consideration when implementing the Singleton pattern in a multi-threaded application?
Using global variables to store the Singleton instance.
Ensuring that only one instance can be created, even under concurrent access.
Creating separate instances for each thread.
Avoiding any form of synchronization to improve performance.
In the Observer pattern, what does the 'subject' object do?
Provides an interface for attaching and detaching observer objects.
Both B and C
Observes the state of other objects.
Maintains a list of its dependents and notifies them of state changes.
In a text editor, which of these actions would be a good candidate for implementing with the Command Pattern?
Changing the font size of the selected text.
Checking for spelling errors in the background.
Displaying a warning message when the user attempts to close the editor without saving.
Rendering the text on the screen.