Which practice helps prevent cycles in a dependency graph?

Get ready for your Object‑Oriented Programming Test. Use flashcards and multiple-choice questions. Each question includes hints and explanations. Prepare for your exam today!

Multiple Choice

Which practice helps prevent cycles in a dependency graph?

Explanation:
Relying on abstractions rather than concrete implementations helps prevent cycles because it decouples who uses something from how it’s implemented. When a module depends on an interface, it only requires the contract, not a specific class, so the dependency points toward a shared boundary rather than back toward another module. The concrete class that implements that interface can live in a separate layer, and the two sides interact through the same abstraction, which tends to orient dependencies in one direction. If a module depends directly on a concrete type, changes or dependencies in that concrete class can ripple outward and back into other modules, creating a cycle. By applying dependency inversion—high-level code depends on abstractions and low-level details implement those abstractions—you can swap implementations without reconfiguring callers, further reducing the risk of circular dependencies. The other practices don’t address this directional decoupling: allowing modules to import each other freely invites cycles, merging everything into one bundle hides cycles rather than prevents them, and depending on concrete implementations directly reinforces tight coupling and can easily form circular links.

Relying on abstractions rather than concrete implementations helps prevent cycles because it decouples who uses something from how it’s implemented. When a module depends on an interface, it only requires the contract, not a specific class, so the dependency points toward a shared boundary rather than back toward another module. The concrete class that implements that interface can live in a separate layer, and the two sides interact through the same abstraction, which tends to orient dependencies in one direction.

If a module depends directly on a concrete type, changes or dependencies in that concrete class can ripple outward and back into other modules, creating a cycle. By applying dependency inversion—high-level code depends on abstractions and low-level details implement those abstractions—you can swap implementations without reconfiguring callers, further reducing the risk of circular dependencies.

The other practices don’t address this directional decoupling: allowing modules to import each other freely invites cycles, merging everything into one bundle hides cycles rather than prevents them, and depending on concrete implementations directly reinforces tight coupling and can easily form circular links.

Subscribe

Get the latest from Examzify

You can unsubscribe at any time. Read our privacy policy