filmov
tv
Single Level Of Abstraction (SLA) Principle In JavaScript
Показать описание
When the code complies with a Single Level of Abstraction principle, it's easy to test, easy to extend, easy to understand, and reuse.
Each abstraction is doing its own job, therefore could be tested separately. Tests asserting a single job are always simple and accurate.
Having each abstraction doing one job also means is has only one reason to change, has a single responsibility (SOLID principles). Enhancing its behavior won't be complicated when a new business requirement comes. We deal with just one thing.
In a composition that is written according to the SLA principle, all elements will have the same level of detail. All abstractions will be presented as function calls. This makes it very easy to understand what is happening without looking at the implementation detail. We read the composition in pure English:
```
if (!hasOrders(orders) {
return createEmptyAmount();
}
return getOrdersTotalAmount(orders);
```
Small abstractions are always easy to reuse. They have none to few dependencies, are small enough to suit various use cases.
All these benefits lead to maintainable software.
Developers read code up to 10 times more than they spend writing it. Let’s employ the Single Level of Abstraction principle in favor to write a code that is easy to maintain for a future us and our teammates.
#SingleLevelOfAbstraction #JavaScript #TypeScript #CleanCode #WeAreGeorge
Each abstraction is doing its own job, therefore could be tested separately. Tests asserting a single job are always simple and accurate.
Having each abstraction doing one job also means is has only one reason to change, has a single responsibility (SOLID principles). Enhancing its behavior won't be complicated when a new business requirement comes. We deal with just one thing.
In a composition that is written according to the SLA principle, all elements will have the same level of detail. All abstractions will be presented as function calls. This makes it very easy to understand what is happening without looking at the implementation detail. We read the composition in pure English:
```
if (!hasOrders(orders) {
return createEmptyAmount();
}
return getOrdersTotalAmount(orders);
```
Small abstractions are always easy to reuse. They have none to few dependencies, are small enough to suit various use cases.
All these benefits lead to maintainable software.
Developers read code up to 10 times more than they spend writing it. Let’s employ the Single Level of Abstraction principle in favor to write a code that is easy to maintain for a future us and our teammates.
#SingleLevelOfAbstraction #JavaScript #TypeScript #CleanCode #WeAreGeorge
Комментарии