A dark image of vines tangling infront of a wall

In the tv-series Stranger things there are tentacles, or maybe vines, spreading through the underworld called “the upside-down”. It’s a scary place of darkness, and the thick dark cords infiltrate and consume. The clinging and squirming things are also connected to each other. Step on one and all the others will know.

There is code like this, frameworks that infiltrate the domain code until they are inseparable. Change one part and it affects all of it. You are never safe to move. Bad habits of the team that designed the framework will seep into the code base. (Regardless if the framework is external or developed alongside the domain logic.) Getting free takes time. Approval tests and safe refactoring are the flamethrowers that can save us.

To avoid this anti-pattern, keep your frameworks at arms length. Isolate code that is framework specific from your domain logic. Use interfaces! Hexagonal design (ports and adapters) can be used for this.

A bonus is that the code will be testable. Frameworks are good at side effects. Let them deal with that. The domain code is then easy to put in unit tests.

If the framework is not working for you, or is updated. Make sure the interface is preserved and the change is mostly done. It won’t even make your nose bleed.

Tags

Comment on the blog!

Create a comment by emailing me. I will then add the comment to the post.

Open an email to start writing.