Header Ads

Header ADS

OOP in a nutshell

OOP or  Oriented Object Programming , is a very common notion in IT field . 

It's a programming concept that concerns of building class and creating objects in order to solve problems . 

The opposite concept is  Functional Programming

https://as1.ftcdn.net/jpg/02/29/98/86/500_F_229988689_RACIuAS5dzZc4UwaeULyjzdO14HK63mO.jpg

Class is  a model or structure thanks to we create instances called objects with the specific format(attribute and methods) . 

Imagine you are in a factory and want to create cars , so you define the model  so that the objects can  be created with the same shape and characteristics.

Why  we invented this concept ? 😕.

Starting to solve problems we got code bigger and bigger.

We have remarked that some data structured are being repeated ,

some functions have common huge number of variables ,

and if we try to scale our project bigger it get messy 😟 and much  more issues . 

So as you guessed the OOP is the savior😍and here's why :

1/Encapsulation : 

it means that data are structured within a defined Class ,each class have a specific attributes and methods . for example :

here the Class Car posses his own attributes that can be only accessed by it.

 


 2/abstraction :

it goes along with the previous concept , it means that the we don't need to show the full info to users !  we show only what is necessary : just like this device you are using .

For a better user experience we don't care about hidden functionalities 😉

3/Inheritance :

It's a very interesting concept in OOP , it allows us to create class for already existing one , since both of them share a common structure or some of it at least!

The one that pass the structure is called parent the child is the one who  get it .

In some programming language it's allowed to have multiple inheritance (one child can inherit from multiple parent ).

This will  help to avoid repeating unnecessary code .for example:

The Rabbit class inherit from  animal . 


4/Polymorphism :

After using inheritance we aim to make some changes with the child .We can re-define methods with the same name and different functionality . in order to fit the new class .

This was a brief explanation of OOP ,it's not a monster just try it 😁😁.

 

 





No comments

Theme images by enot-poloskun. Powered by Blogger.