OOP — Object Oriented Programming
Today is day 9 of Dev League and I’ve already learned tons! We have been learning about Object Oriented Programming for the past two days, so now I will do my best to explain to you what OOP is like a five year old.
First off, why would we want to use OOP? There are couple of reasons:
- We can organize our code
- Easier for code to make sense to you
- Promotes the DRY(Don’t Repeat Yourself) principle
- Promotes encapsulation(1 of the 4 pillars of OOP)
Exposes relevant functions. Reduces code complexity and irrelevant detail, which makes your code aesthetically pleasing.
The process of putting in data and functions in a class(blueprint). This data is now hidden and can’t be accessed by anyone else.
Pretty much means, that you can create a children class that inherit s its properties and methods from a parent class.
The word polymorphism means that you can change into different stages. That means that a children class can have properties and methods of its own, but still keep properties of its parent class.
So there are two things that make up OOP, classes and Objects:
Classes are like blueprints for how objects are structured and how they should behave.
Objects are instance of class , so whatever objects that are constructed from the classes all share the same property and methods.
Classical inheritance vs. Prototypical Inheritance
In classical inheritance, when you create a class and then instantiate it, the instance is now divorced from the class.