Today I was having a discussion on twitter, and after re-reading my timeline and seeing this tweet, I decided to blog about it.
This is the gist of it
|OO||Required||To be avoided|
|FP||To be avoided||Required|
A small explanation
Encapsulation vs abstraction
Demis’ tweet explains it perfectly:
OO thrives on encapsulation:
- Behaviour is captured in systems, hiding the concrete types and data.
- System interactions use purpose-built integration points/contracts (i.e.
- Composition happens using explicit contracts, and usually requires an integration system/- class.
FP thrives on abstraction
- Behaviour is captured in functions that have a precise notion of the type/parameter’s meaning.
- System design is driven by this meaning and creating new types/meanings.
- As functions have a precise notion on this meaning, one can easily compose behaviour by chaining functions.