The Big Picture of OOP
When I was studying object-oriented programming course at school, I always got questions from my colleagues like :
- “What is the meaning of OOP ?”
- “What is the difference between normal coding (procedural programming) and OOP ?”
And I have never forgot my answer !
- “Have u create a class ?”
- “Yes, I have !”
- “Welcome to OOP world.”
Object-Oriented Programming (OOP)
Object-oriented programming is simply the art of making and using objects. In other funny words, is to make your code oriented to object.
Classes and Objects
The object is a single unit of data and functions that operate on that data.
To create an object, you need a class ! The object has the same relationship to a class that a variable has to a data type.
So ? yes, the object is an instance of a class.
No more bla ! Let’s do some action ??
Now, we have created our class (the new data type ??)
Let’s use it …
That’s it ??
What’s Going On ?
One benefit of OOP is the close corresponding between real-world objects and OOP classes ??
Think in terms of objects. For example, if you are developing a program that works around user, that’s a mark to go on and create a class (close correspondence)
In our example, we have created a class called “person” and we have added the attributes of person we concerns about in the object data and because of we have two operations which play around each person, we created two functions in our class.
Thanks to OOP, the close correspondence makes the process easy and awesome ??
Behind The Code !
By encapsulating the data and the functions that operate on that data into a single unit, let’s see what we have achieved yet !
- Restricted access
- Re-usability
- Data hiding
1. Restricted Access
Our functions have only an access to the data in object. In procedural programming, the functions have unrestricted access to global data which may be defined to be used by another function ??
In OOP, the functions have the right access to the right data ??
2. Re-usability
Once a class has been written, created and debugged, you can reuse it in other programs and it can also be distributed to other developers (I make this kind of work every new project ??)
3. Data Hiding
You can not access the data in the class directly, you can only access “name” and “age” (defined in the class) through the member functions (functions that are defined in the class are called member functions)
Literally, you hide the data from the outer world !
Why ? That makes our data safe from accidental alteration ??
Cut ??
Our journey has ended, I hope it was awesome for u (as it acted for me).
The main goal behind this article is to understand the world of OOP and how it works (beginner guide) and remember that’s not the whole thing about OOP, it’s only … u know, The Big Picture ??
My expectation is to understand OOP with a percentage above 50%, that’s cool and this is a great start to work around !
There is a lot to read and a lot to learn about OOP, I wish the road is now more clear and dust free than before … see u ??
PHP Developer at UESystems
5 年Speak On Algorithm please? and clean code , thanks?