Practice
Solution
Step 1: Understand interface role
Interfaces declare methods but provide no implementation or constructors.Step 2: Abstract class constructor behavior
Abstract class constructors run during instantiation to initialize shared state.Step 3: Implementation of interface methods
The class implementing the interface provides method bodies; no constructor or code runs from interface itself.Final Answer:
Option A -> Option AQuick Check:
Interfaces define contracts only; abstract class constructors run during instantiation.
- Thinking interface methods have constructors or code to execute.
- Believing interface implementation order affects constructor execution.
- Confusing interface method implementation with constructor invocation.
Solution
Step 1: Understand ISP's goal
ISP aims to prevent clients from depending on methods they don't use, avoiding fat interfaces that force unnecessary implementations.Step 2: Analyze options
When clients depend on interfaces that contain methods they do not use, causing unnecessary implementation burden. correctly identifies the scenario where ISP helps by splitting fat interfaces. When all clients require the exact same set of methods, so a single fat interface simplifies design. describes a scenario where ISP is less needed. When you want to enforce a strict inheritance hierarchy with minimal interfaces. confuses inheritance hierarchy with interface segregation. When you want to reduce the number of interfaces to simplify the codebase. incorrectly assumes fewer interfaces always simplify design, ignoring interface misuse.Final Answer:
Option A -> Option AQuick Check:
ISP is about splitting interfaces to avoid forcing clients to implement unused methods.
- Believing fewer interfaces always mean better design
- Thinking ISP applies when all clients use all methods
- Confusing ISP with inheritance hierarchy rules
Solution
Step 1: Recall Facade's purpose
Facade simplifies complex subsystems by providing a unified interface.Step 2: Analyze trade-offs
While Facade simplifies usage, it can hide advanced features, limiting flexibility.Step 3: Evaluate other options
A is incorrect because Facade reduces coupling by hiding subsystem details. C is incorrect; Facade's overhead is minimal. D is wrong; Facade does not require changing subsystems.Final Answer:
Option A -> Option A
- Believing Facade increases coupling instead of reducing it
- Assuming Facade adds heavy runtime overhead
- Thinking Facade requires modifying subsystems
Solution
Step 1: Review Adapter intent
Adapter converts incompatible interfaces to make them compatible.Step 2: Check each statement
A is correct: Adapter changes interface. B is correct: Adapter can use inheritance or composition. C is correct: Adapter can add behavior without modifying original object. D is incorrect: Simplifying a complex subsystem is Facade's role, not Adapter's.Final Answer:
Option D -> Option D
- Confusing Adapter with Facade's simplification role
- Thinking Adapter only uses inheritance
- Assuming Adapter cannot add new behavior
Solution
Step 1: Embedding snakes/ladders inside Board
This approach simplifies initial design but tightly couples Board to these elements.Step 2: Impact on extensibility
Tightly coupled design makes it harder to add new board elements (e.g., portals, traps) without modifying Board.Step 3: Modeling as separate entities
Allows easy extension by adding new element types without changing Board internals.Step 4: Complexity and memory considerations
Separate entities add minimal overhead; runtime complexity impact is negligible.Final Answer:
Option B -> Option BQuick Check:
Trade-off is between simplicity and extensibility, not runtime complexity or memory bloat.
- Thinking separate entities cause big runtime overhead
- Believing embedding improves encapsulation and immutability
- Assuming separate entities cause memory bloat
