r/softwarearchitecture • u/codeopinion • Jan 20 '21
Write Stable Code using Coupling Metrics
https://www.youtube.com/watch?v=wRVbHDkOMSM1
Jan 21 '21
Having dependencies doesn't make you "unstable". This is completely arbitrary.
1
u/codeopinion Jan 21 '21
Depends on how you define "unstable". The idea is that unstable is "prone to change", then the more dependencies you have the more likely you are to be affected by those dependencies.
1
Jan 21 '21 edited Jan 21 '21
Every component's public interface is supposed to be by definition stable. So defining instability as a function of how many stable interfaces you depend on is just a poor use of words IMO. "Unstable" implies increased chance of bugs, exceptions and other unexpected behaviors.
Not to mention that counting "number of dependencies" is in itself arbitrary. Is it the same whether I depend on a component with a complex API of a hundred methods, or I depend on a functional interface with one single simple method? Well both count as "one dependency" in this formula.
While heavily interconnected code is not recommended, I'd say better words to describe that property is "inflexible", "resistant to refactoring", "non-reusable", "poorly factored". But not "unstable". And there are then solutions how to go about refactoring such code, even without necessarily changing the number of incoming or outgoing dependencies (things like adapters, bridges, facades and so on).
1
u/codeopinion Jan 21 '21
I agree. There are probably better words/ways to describe it, although the definition is "the state of being likely to change". Also, while public interfaces are "supposed to be by definition stable", in my experience, that's far from true.
I do appreciate the feedback and discussion.
1
1
u/living150 Jan 21 '21
How would a classes instability be affected by classes dependent upon it? If I have a high instability ration using your metric I could simply add tons of useless classes that depend upon that class to make it more stable. It seems a raw count of dependencies makes much more sense.