OO vs FP
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
Encapsulation | Abstraction | |
---|---|---|
OO | Required | To be avoided |
FP | To be avoided | Required |
A small explanation
Encapsulation vs abstraction
Demis' tweet explains it perfectly:
@ashic @ToJans @abdullin @NeilRobbins information hiding is encapsulation, creating layers is abstraction
— Demis Bellot (@demisbellot) 24 juni 2014
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.
public
and/orinterfaces
). - 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.