cln.co/
SLA
SLASingle Level of Abstraction

"Code should read like a story, not a detective novel" - Danial Markham

Key Takeaways
  • Keeping one level of abstraction makes code more readable.
  • Using the same abstraction lets us keep less context in our head.
  • It's easier to write and maintain code that's organized around a single level of abstraction.

Description

Each method should be written in terms of a single level of abstraction.

Break down your code so that each piece operates at one level of detail. For example, one function could focus on the big picture (like making a sandwich), while another handles a specific task (like slicing tomatoes).

"Within a certain method we look to keep all the code at the same level of abstraction to help us read it more easily." Robert C. Martin

Mixing simple commands with complex logic in the same function or class can make your code a jumbled mess that's tough to follow and maintain.

"In order to make sure our functions are doing ‘one thing’, we need to make sure that the statements within the function are all at the same level of abstraction" - Robert C. Martin

You might also like:
ADP
APO
BSR
CCP
CoI
CQS
CRP
DIP
DRY
EUHM
EWV
FF
FTSE
GRASP
HC
HLYW
IH
IoC
IOSP
ISP
KISS
LC
LoD
LOLA
LSP
OCP
POLP
POLS
PoMO
REP
RoT
RTFM
SAP
SDB
SDP
SLA
SoC
SOLDIER
SOLID
SPOT
SRP
TdA
WET
YAGNI
ZOI