Small changes yield unexpected problems.
TL;DR: If small changes have big impact, you need to decouple your system.
Problems
- Coupling
Coupling: The one and only software design problem
Maxi Contieri ・ Feb 6 '21
Solutions
- Decouple.
- Cover with tests.
- Refactor and isolate what is changing.
- Depend on interfaces.
Examples
- Legacy Systems
Sample Code
Wrong
class Time {
constructor(hour, minute, seconds) {
this.hour = hour;
this.minute = minute;
this.seconds = seconds;
}
now(){
//call operating system
}
}
//Adding a TimeZone will have a big Ripple Effect
//Changing now() to consider timezine will also bring the effect
Right
class Time {
constructor(hour, minute, seconds, timezone) {
this.hour = hour;
this.minute = minute;
this.seconds = seconds;
this.timezone = timezone;
}
//Removed now() since is invalid without context
}
class RelativeClock {
constructor(timezone){
this.timezone = timezone;
}
now(timezone){
var localSystemTime = this.localSystemTime();
var localSystemTimezone = this.localSystemTimezone();
//Do some math translating timezones
//
return new Time(..., timezone);
}
}
Detection
- It is not easy to detect problems before they happen. Mutation Testing and root cause analysis of single points of failures may help.
Tags
- Legacy
Conclusion
There are multiple strategies to deal with Legacy and coupled systems. We should deal with this problem before it explodes under our eyes.
Relations
More info
Credits
Photo by Jack Tindall on Unsplash
Architecture is the tension between coupling and cohesion.
Neal Ford
Software Engineering Great Quotes
Maxi Contieri ・ Dec 28 '20
This article is part of the CodeSmell Series.
How to Find the Stinky parts of your Code
Maxi Contieri ・ May 21 '21
Last update: 2021/06/24
Top comments (0)