Notes on component coupling

Acyclic Dependencies Principle (ADP)

ADP comes from the Telecommunication industry. The purpose is to solve the “morning after syndrome”. The “morning after syndrome” refers to the situation in which a developer goes to work in the morning to find his codes no longer working because someone has changed something which his codes depend on.

Stable Dependencies Principle (SDP)

Component A is stable if it has other components that depend on it. The degree of stability is proportional to the number of dependents. The more dependents A have, the more stable A is.

Measuring stability of a component

Fan-in = Number of classes outside the component which depends on the component.

Stable Abstractions Principle (SAP)

In a software system, we may have certain high level policies which we don’t expect to change often. Those policies can be business rules, validations, architecture patterns etc … At the same time, we don’t want to make it difficult to change the high level policies. How can we keep the high level policies stable yet extendable? One way is to place the policies in stable components consisting of abstract classes and interfaces. In fact, SAP suggests stable components which have dependent components should be abstract. The more abstract a stable component is, the less impact any changes to it may have on its dependents. In contrast, unstable components which have no dependent components should consist of concrete classes.

Measuring abstraction

To measure the abstractness of a component, we can divide the number of abstract classes and interfaces in the component by the total number of classes in the component.

Conclusion

Together, the three principles provide solid guidelines for designing loosely coupled components. To comply with ADP, dependencies between components should have no cycle. To comply with SDP, dependencies should go in the direction of decreasing instability. That means, a dependent component should be less stable than the components it depends on. To comply with SAP, the stable parts of a component which others depend on should be abstract, and the volatile parts of the component which depend on other components should be concrete.

References

Clean Architecture: A Craftsman’s Guide to Software Structure and Design

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Tai Bo

Tai Bo

Backend developer in .NET core. I enjoy the outdoor, hanging out with good friends, reading and personal development.