Grasp and others
Q1: What is the purpose of Structural Patterns?
A1: Define relationships between entities to form larger, flexible structures.
Q2: How does the Adapter Pattern help with legacy systems?
A2: Converts an existing interface into one that clients expect by wrapping the class with a new interface.
Q3: When can the Proxy and Adapter patterns complement each other?
A3: A Proxy controls access to an object, and an Adapter converts its interface for compatibility.
Q4: Why is the Composite Pattern useful for managing hierarchies?
A4: Organizes objects into a tree structure, treating single and group objects the same.
Q5: How does the Decorator Pattern add flexibility to Structural Patterns?
A5: Wraps objects to add new behavior at runtime without changing their structure.
Q6: What is the purpose of Behavioral Patterns?
A6: Assign responsibilities between objects and define communication between them.
Q7: How does the Chain of Responsibility differ from Strategy?
A7:
Chain: Passes a request through a chain of handlers.
Strategy: Selects behavior (algorithm) at runtime from a family of options.
Q8: When would you use the Observer Pattern?
A8: To create a one-to-many relationship where changes in one object notify all dependents.
Q9: What is a drawback of the Observer Pattern?
A9: Can cause performance issues if there are too many observers or frequent updates.
Q10: How does the State Pattern enable flexibility?
A10: Allows an object’s behavior to change when its internal state changes, appearing as if it has changed its class.
Q11: What is the main benefit of separating intrinsic and extrinsic state in the Flyweight Pattern?
A11: Reduces memory usage by sharing intrinsic (common) state while keeping extrinsic (unique) state separate.
Q12: In which type of applications is the Flyweight Pattern most beneficial?
A12: Applications with many similar objects, like simulations or dense UIs.
Q13: How do you avoid a God Object in the Flyweight Pattern?
A13: Keep Flyweight focused on shared data and delegate unrelated tasks to other objects.
Q14: How does the Composite Pattern differ from the Decorator Pattern?
A14:
Composite: Manages object hierarchies.
Decorator: Wraps single objects to add new behavior dynamically.
Q15: How do the Proxy and Decorator patterns overlap?
A15: Both involve an intermediate object:
Proxy: Controls access.
Decorator: Adds functionality.
Q16: What is the main purpose of the Singleton Pattern, and what are its disadvantages?
A16:
Purpose: Ensure one instance of a class exists.
Disadvantage: Creates global state, harder to test and maintain.
Q17: How does the Strategy Pattern improve flexibility?
A17: Organizes algorithms into separate classes and allows runtime selection of behavior.
Q18: What potential drawbacks can arise from using the Factory Method Pattern?
A18: Can add complexity by introducing many subclasses.
Q19: When would you use the Builder Pattern instead of a Factory Method?
A19: When constructing complex objects step-by-step with many optional components.
Q20: How does Polymorphism reduce the need for conditionals?
A20: It delegates behavior variations to subclasses, avoiding if-else statements.
Q21: What is the purpose of using interfaces when designing systems?
A21: Define boundaries between layers, promoting flexibility and decoupling dependencies.
Q22: Why is using new() problematic for dependencies?
A22: Ties code to specific implementations, making it harder to test or manage changes.
Q23: What are the benefits of the Factory Approach?
A23: Decouples object creation from usage, enabling easier testing and runtime substitution.
Q24: How can factories enable test-time injection?
A24: Factories create mock or test versions of components for controlled testing.
Q25: How does the Abstract Factory differ from the Factory Method?
A25:
Abstract Factory: Creates families of related objects.
Factory Method: Lets subclasses define which object to create.
Q26: Why are interfaces critical for variance in design?
A26: Allow different implementations without changing higher-level code.
Q27: How does the Factory Approach improve testability?
A27: By injecting test objects instead of concrete implementations.