2023-10-19


Classes - Public, private, protected
In classes you can have public, private or protected properties/methods.
Public means that it is public, you can edit it from outside the class.
Private means that it is private, you can’t edit it from outside the class.
Protected means that it is protected, you can’t edit it from outside the class except if it’s in a derived sub class.
Normally you add underscores in front of private/protected properties and use getters/setters to interact with them instead.
Four pillars of OOP
There are four pillars of OOP:
  1. Data Hiding: Concept: Protecting data from direct external access. In JavaScript: Use closures or private variables to limit access to specific properties.
  2. Inheritance: Concept: Creating new objects based on existing ones. In JavaScript: Implement inheritance through prototype chains or ES6 class inheritance.
  3. Polymorphism: Concept: Treating different objects as if they’re of a common type. In JavaScript: Achieve polymorphism by method overriding or function overloading.
  4. Encapsulation: Concept: Bundling data and methods into a single unit (class). In JavaScript: Use object literals or class definitions to group related data and functions for clean and modular code.
Thanks chatgpt! 😇
Go back to all posts