JavaScript Scene
Published in

JavaScript Scene

The Forgotten History of OOP

Smoke Art Cubes to Smoke — MattysFlicks — (CC BY 2.0)

The Big Idea

“I made up the term ‘object-oriented’, and I can tell you I didn’t have C++ in mind.” ~ Alan Kay, OOPSLA ‘97

  • Message passing
  • Encapsulation
  • Dynamic binding

The Essence of OOP

  • Avoiding shared mutable state by encapsulating state and isolating other objects from local state changes. The only way to affect another object’s state is to ask (not command) that object to change it by sending a message. State changes are controlled at a local, cellular level rather than exposed to shared access.
  • Decoupling objects from each other — the message sender is only loosely coupled to the message receiver, through the messaging API.
  • Adaptability and resilience to changes at runtime via late binding. Runtime adaptability provides many great benefits that Alan Kay considered essential to OOP.
  • Objects
  • First-class functions and closures
  • Dynamic types
  • Late binding (functions/methods changeable at runtime)
  • OOP without class inheritance
  • Encapsulation
  • Message passing
  • Dynamic binding (the ability for the program to evolve/adapt at runtime)
  • Classes
  • Class inheritance
  • Special treatment for objects/functions/data
  • The new keyword
  • Polymorphism
  • Static types
  • Recognizing a class as a “type”
fmap :: (a -> b) -> f a -> f b
// isEven = Number => Boolean
const isEven = n => n % 2 === 0;
const nums = [1, 2, 3, 4, 5, 6];// map takes a function `a => b` and an array of `a`s (via `this`)
// and returns an array of `b`s.
// in this case, `a` is `Number` and `b` is `Boolean`
const results = nums.map(isEven);
console.log(results);
// [false, true, false, true, false, true]
// matches = a => Boolean
// here, `a` can be any comparable type
const matches = control => input => input === control;
const strings = ['foo', 'bar', 'baz'];const results = strings.map(matches('bar'));console.log(results);
// [false, true, false]

What is an Object?

OOP is not Real OOP Anymore

  • Programming with components (Alan Kay’s “object”)
  • Component state must be encapsulated
  • Using message passing for inter-object communication
  • Components can be added/changed/replaced at runtime

What Good MOP Looks Like

Learn More at EricElliottJS.com

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store