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.
There are four pillars of OOP:
- Data Hiding: Concept: Protecting data from direct external access. In JavaScript: Use closures or private variables to limit access to specific properties.
- Inheritance: Concept: Creating new objects based on existing ones. In JavaScript: Implement inheritance through prototype chains or ES6 class inheritance.
- Polymorphism: Concept: Treating different objects as if they’re of a common type. In JavaScript: Achieve polymorphism by method overriding or function overloading.
- 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! 😇