Skip to content

Latest commit

 

History

History
9 lines (8 loc) · 766 Bytes

File metadata and controls

9 lines (8 loc) · 766 Bytes
rule_id 1020
rule_category class-design
title Avoid bidirectional dependencies

This means that two classes know about each other's public members or rely on each other's internal behavior. Refactoring or replacing one of those classes requires changes on both parties and may involve a lot of unexpected work. The most obvious way of breaking that dependency is to introduce an interface for one of the classes and using Dependency Injection.

Important

Exception: Domain models such as defined in Domain-Driven Design tend to occasionally involve bidirectional associations that model real-life associations. In those cases, make sure they are really necessary, and if they are, keep them in.