Learn object-oriented programming from scratch
Hello! Welcome
Today we are going to explore Object-Oriented Programming from Scratch
What is Object-Oriented Programming?
Object-Oriented Programming (OOP) is a way of programming that organizes code into objects.
An object is a piece of code that represents an entity from the real world.
What is Object-Oriented Programming?
Objects have
The attributes, which are data it contains
The methods, which are actions it can perform
Why use OOP?
Objects help to organize by breaking the code into small manageable pieces
Then you put them together, relate, and communicate between them to make your program as if it were a puzzle!
You’re doing great!
Now let’s talk about how to use objects
How does a class work?
A class is like a mold for creating objects.
In the class, we define the attributes and methods that the objects created from it will have.
Creating instances
Now we can use the class to create instances.
Each instance will have its own attributes and methods defined in the class.
Interfaces
Classes are not the only way to define objects. There are more advanced ones like abstract classes or interfaces.
You will learn how to use them and the difference between them gradually.
We’re almost there!
Object-oriented programming has several fundamental pillars.
Inheritance
Inheritance allows you to create a new class based on an existing class.
This means that the new class inherits attributes and methods from the base class and can add or modify functionalities.
Encapsulation
Encapsulation protects the internal elements of an object by controlling what the rest can modify.
This is achieved through the use of access modifiers such as public
, private
, and protected
.
Polymorphism
Polymorphism allows using a common interface for different types of objects.
For example, different classes can implement a method with the same name but with specific behaviors.
Well done!
Now you have the basics to continue learning about Object-Oriented Programming Enjoy the journey!