Skip to content

Instantly share code, notes, and snippets.

@ToJans
Last active August 29, 2015 14:02
Show Gist options
  • Save ToJans/7ff1786dfcbdf99df5da to your computer and use it in GitHub Desktop.
Save ToJans/7ff1786dfcbdf99df5da to your computer and use it in GitHub Desktop.
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
<script async src="//platform.twitter.com/widgets.js" charset="utf-8"></script>

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/or interfaces).
  • 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 the this meaning and creating new types/meanings.
  • As functions have a precise notion on this meaning, one can easily compose behaviour by chaining functions.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment