OOP in JS

OOP is a programming paradigm based on the concept of "objects", which can contain data and code: data in the form of fields (often known as attributes or properties), and code, in the form of procedures (often known as methods).

What is OOP?

4 Pillars of OOP

  • Encapsulation
    • Reduce complexity + increase reusability
  • Abstraction
    • Reduce complexity + isolate impact of change
  • Inheritance
    • Eliminate redundant code
  • Polymorphism
    • Eliminate ugly if-else/switch statements

Example: localStorage

Encapsulation (info hiding)

Exposing only the minimum required by a public interface

Keeping the data and the code together in a unified way

Benefits

  • Code refactoring
  • Preventing misuse of object's state
  • Better modularity

Example: Question

OOP in JS

By Arfat Salman