What is a key difference between a deep copy and a shallow copy in the context of the Prototype Pattern?
Explanation:
This difference is crucial in Prototype. Deep copies prevent unintended side effects by ensuring that modifications on cloned objects don't impact the original prototypes or their nested members.
How does the Composite pattern promote code reusability?
Explanation:
The Composite pattern allows clients to treat individual objects and compositions of objects uniformly through a shared interface. This makes the code more flexible and reusable.
In which scenario would the Prototype Pattern be LESS suitable?
Explanation:
If creating objects is already cheap and straightforward, the overhead of implementing the Prototype Pattern might outweigh its benefits. It shines when object instantiation is expensive.
How does the Builder Pattern differ from using telescoping constructors?
Explanation:
Unlike telescoping constructors, which become unwieldy with numerous parameters, the Builder Pattern offers a structured approach for constructing objects with multiple attributes, particularly when many are optional.
In the Flyweight pattern, what is the role of the 'intrinsic state'?
Explanation:
Intrinsic state represents the shareable aspects of objects in the Flyweight pattern. This data is independent of the object's context and remains constant.
Which real-world scenario is well-suited for the Composite pattern?
Explanation:
A file system is a classic example of the Composite pattern. Directories can contain files (leaves) and other directories (composites), forming a tree-like structure.
Which of these is NOT a common use case for the Prototype Pattern?
Explanation:
While Prototype can be used alongside a factory method, they serve distinct purposes. Factory Method focuses on providing an interface for object creation without specifying the exact class, while Prototype deals with object creation through cloning.
In the Builder Pattern, what is the role of the 'Director'?
Explanation:
The Director class in the Builder pattern is responsible for controlling the object construction process. It uses a concrete Builder instance to assemble the parts of the complex object in a specific order.
What type of relationship does the Composite pattern leverage to represent the parent-child structure?
Explanation:
The Composite pattern uses composition to build the tree-like structure. A composite object 'owns' its children, and the children cannot exist independently of the parent.
How does the Iterator Pattern contribute to code maintainability?
Explanation:
The decoupling provided by the Iterator Pattern enhances maintainability as modifications to the iteration process or the underlying collection's structure can be made without impacting each other.