Add daily email for 2024-03-04
Why you need layers in your application code
This commit is contained in:
parent
47b953641f
commit
51dfb52677
32
source/_daily_emails/2024-03-04.md
Normal file
32
source/_daily_emails/2024-03-04.md
Normal file
|
@ -0,0 +1,32 @@
|
|||
---
|
||||
title: Why you need layers in your application code
|
||||
date: 2024-03-04
|
||||
permalink: archive/2024/03/04/why-you-need-layers-in-your-application-code
|
||||
tags:
|
||||
- software-development
|
||||
- software-architecture
|
||||
- clean-code
|
||||
cta: ~
|
||||
snippet: |
|
||||
Why should you make your code more robust and flexible by introducing layers into your code?
|
||||
---
|
||||
|
||||
You need to add an integration with a new service or supplier to your application code.
|
||||
|
||||
You should avoid writing code that interacts directly with that service or supplier - a.k.a tightly-coupled code.
|
||||
|
||||
What if you change to a different service or supplier in the future?
|
||||
|
||||
What if they release a new version of their API that includes breaking changes?
|
||||
|
||||
If your code is tightly coupled to a single implementation, you'd need to rewrite the code, and there wouldn't be a way to easily switch from the old version to the new one.
|
||||
|
||||
By introducing an adapter layer, you make your code more loosely coupled.
|
||||
|
||||
You can have multiple implementations, with one for each different supplier, service, or version.
|
||||
|
||||
You can have a consistent interface and API for every implementation, making them hot-swappable and making it easy to switch between different implementations.
|
||||
|
||||
If you change supplier or they release a new version, you write a new implementation for it and switch when you're ready.
|
||||
|
||||
Also, as every implementation satisfies a common interface, it's easy to make a fake implementation that you can use for testing.
|
Loading…
Reference in a new issue