What is the primary intent of the Composite Design Pattern?
To provide a way to access the elements of an aggregate object sequentially.
To treat individual objects and compositions of objects uniformly.
To ensure a class has only one instance.
To define a family of algorithms, encapsulate each one, and make them interchangeable.
What type of Proxy is used to control access to a resource based on access rights?
Protection Proxy
Caching Proxy
Remote Proxy
Virtual Proxy
Which real-world scenario is well-suited for the Composite pattern?
Creating a thread-safe singleton object.
Implementing an undo/redo mechanism.
Managing a database connection pool.
Representing a file system with directories and files.
What is a key difference between a deep copy and a shallow copy in the context of the Prototype Pattern?
A deep copy is faster to execute than a shallow copy.
A shallow copy is preferred when you need to maintain object immutability.
A shallow copy duplicates references, while a deep copy creates new instances for nested objects.
A deep copy is only applicable to immutable objects.
In which scenarios is the Iterator Pattern particularly valuable?
When the internal representation of a collection is subject to change.
All of the above.
When you want to provide a consistent way to traverse elements regardless of the collection type.
When multiple algorithms need to operate on a collection without knowledge of its internal structure.
In a GUI toolkit using the Composite pattern, what would a 'Dialog Box' be considered?
Iterator
Client
Leaf
Composite
How does the State Pattern differ from a simple switch statement for managing state?
The State Pattern distributes state-specific logic, improving maintainability.
The State Pattern is less verbose than using a switch statement.
A switch statement is more aligned with object-oriented principles.
The State Pattern is only suitable for complex state machines.
Which of the following is a key characteristic of a Proxy object in the Proxy Pattern?
It provides an identical interface to the real subject object.
It must implement a different interface than the real subject object.
It always has direct access to the real subject object.
It cannot modify the behavior of the real subject object.
How does the Flyweight pattern contribute to object-oriented design principles?
It promotes loose coupling by separating object creation from usage.
It improves performance by reducing the number of objects instantiated.
It enhances code reusability by encapsulating common behavior in shared objects.
Which of these is a real-world scenario where the State Pattern is beneficial?
Representing the different stages of an order in an e-commerce system.
Sorting a list of elements in ascending order.
Implementing a simple counter.
Validating user input in a form.