Thursday, May 19, 2016

An Introduction to Object Oriented Programming in Python - Part 1

What is Object Oriented Programming (OOP)?

Object Oriented Programming (OOP) is a very broad topic to be covered in complete details in just a single blog post article. So, I will spread this Introduction to OOP across multi parts of the blog post.

In this part 1, I will introduce, define and explain OOP and some common terminologies used in OOP world with focus on Python Programming Language.

By now you should be aware that Python just like Java, C#, or PHP has a very strong support for Object Oriented Programming (OOP).

What is Object Oriented Programming (OOP)?



INTRODUCTION
Let’s quickly take a look at the general background of “Object Oriented Programming (OOP)” as applicable to most languages that support Object-Oriented concepts.

There are different kinds of programming paradigms; OOP is just one of such paradigms that create “objects” during the phase of programming.
The first object oriented language was Simula-67; Smalltalk followed soon after as the first "pure" object-oriented language. Many languages designed from the 1980s to the present have been object-oriented, notably C++, Python, Java, C#, Ruby, JavaScript and PHP.

The word paradigm is used a great deal when talking about programming languages. What does it mean?
A programming paradigm is a style or “way” of programming. Some languages make it easy to write in some paradigms but not others.

List of Common Paradigms
Some of the more common paradigms are listed below;-


Object Oriented Programming is much more similar to the way the real-world works; it is comparable to the human brain. A message must be sent requesting the data, just like people must ask one another for data/information since we cannot see inside each other’s heads.
In OOP, data and functionality are combined and wrapped inside what is called an “object” (in other words; each program is made up of many entities called “objects”). These objects have state (attribute) and behavior (method). OOP is based on the sending of messages to objects. Objects respond to messages by performing operations.

Now, after reading all these background intro on OOP you should be able to define what it is. Below are some notable definition that cuts across different authors.

DEFINITION OF OOP
OOP: is a programming style of doing real world thinking and simulating the real world in computer programs.

OOP: is a programming paradigms that creates “objects” during the phase of programming.

OOP: is an approach to problem solving where all computations are carried out using objects.

Objects are similar to real world entities, every object has two things namely: Attributes and Methods (that is: Properties and Behaviors).

OOP correlates the real world entities (objects) properties and behaviors. These properties and behaviors of objects are often called with different name by different programming authors as follow:-
Properties are also called: Attributes, Variables, Data members, Fields, Characteristics
Behaviors are also called: Methods, Fucntion members, Actions, Procedures

However, I prefer to call them: Attributes and Methods

Python has been an object-oriented language since it existed. Because of this, creating and using OOP concepts are downright easy.

DEFINITION OF TERMINOLOGIES
There are quite a few alike and frequently used terminologies in OOP, I will define them down below.

Don't worry at this stage if you don't understand the meaning of the terms below. As we use them there meaning will be come clearer and you can always refer back here to check the definitions again.

Class: A user-defined prototype for an object that defines a set of attributes that characterize any object of the class. The attributes are data members (class variables and instance variables) and methods, accessed via dot notation.

Class variable: A variable that is shared by all instances of a class. Class variables are defined within a class but outside any of the class's methods. Class variables are not used as frequently as instance variables are.

Data member: A class variable or instance variable that holds data associated with a class and its objects.

Function overloading: The assignment of more than one behavior to a particular function. The operation performed varies by the types of objects or arguments involved.

Instance variable: A variable that is defined inside a method and belongs only to the current instance of a class.

Instance: An individual object of a certain class. An object obj that belongs to a class Circle, for example, is an instance of the class Circle.

Instantiation: The creation of an instance of a class.

Method: A special kind of function that is defined in a class definition.

Object: A unique instance of a data structure that's defined by its class. An object comprises both data members (class variables and instance variables) and methods. Data + Method = Object

Operator overloading: The assignment of more than one function to a particular operator.

Terms like Inheritance, Encapsulation, Polymorhism are considered as the Pillars of OOP. They will be disused in details in coming parts of this article series.

Don't worry at this stage if you don't understand the meaning of the terms above. As we use them there meaning will be come clearer and you can always refer back here to check the definitions again.

The next Part 2 will discuss Using OOP in Python.


Thank for reading

Reference Materials are here

No comments:

Post a Comment