Skip to main content

Kickstart to Object Oriented Concepts

There are three widely used programming paradigms are: procedural programming, functional programming, and object-oriented programming. Python supports all three programming paradigms.

Object-oriented programming

Object-oriented programming (OOP) is a programming paradigm that uses objects and their interactions to design applications and computer programs.

OOPs is based on four concepts:

1. Inheritance
2. Polymorphism
3. Abstraction
4. Encapsulation

Object and Classes

Everything in Python is an object. Objects are basic building blocks of a Python OOP program.
To create user defined object, we have to first create a class. Actually a class is a blueprint that defines a nature of a future object.
From classes we construct objects. An object is a specific instance of a particular class. So basically, Classes are basically templates thru which we create different objects. 
Classes may contain class variables, methods etc.

Note
It is a convention to give classes a name that starts with a capital letter.
Example: EmailGenerator, Sample etc.
Integers, strings, lists, dictionaries, tuples, functions, and modules are Python objects. The type() function returns the type of the object specified. These objects are built-in objects of the Python programming language.

OOPs Concepts

There are some basic programming concepts in OOP:

1. Abstraction

Abstraction is used to hide internal details and show only functionalities to other intended users. Here, by other intended user, we mean another software application, or another class, or other client who will be the end users of the program.

Abstracting something means to give names to things, so that the name captures the core of what a function or a whole program does.

2. Encapsulation

It can also be said data binding. Encapsulation is all about binding the data variables and functions together in class.

Examples

Abstraction: Suppose you are going to an ATM to withdraw money. You simply insert your card and click some buttons and get the money. You don’t know what is happening internally on press of these buttons. Basically you are hiding unnecessary information from user. So, abstraction is a method to hide internal functionalities from user.

Encapsulation: Suppose there is a tree. Now a tree can have its components like root, stem, branches, leaves, flowers and fruits. It has some functionalities like Photosynthesis. But in a single unit we call it a tree. In same way encapsulation is a characteristic to bind data members and functions in single unit.

3. Polymorphism

It means, something which has many forms.
The polymorphism is the process of using an operator or function in different ways for different data input.

4. Inheritance

The inheritance is a way to form new classes using classes that have already been defined.

Inheritance is a way to reuse once written code again and again. The class which is inherited is called the Base class & the class which inherits is called the Derived class. They are also called parent and child class.

So when, a derived class inherits a base class, the derived class can use all the methods (functions) which are defined in base class, hence making code reusable.


Source: Internet