Object-Oriented Programming
Object-Oriented Programming (OOP) is a computer programming paradigm that focuses on the software design around data or objects, rather than focusing on logic and functions. An object in this methodology is regarded as the data field that has distinctive attributes and possesses a unique behaviour. So, if compared with procedural language methodology, OOPs methodology aims directly at the data for its processing. The main aim of this programming realm is to associate data together with functions that operate on them and this ensures that no other part of the code can access that data except the function that is associated with it. Further in this blog, we will get to know the significance of objects. OOPs concept is built upon three different coding principles namely polymorphism, inheritance, and encapsulation, we will highlight these topics in our upcoming sections.
We now have a basic concept of what Object-Oriented Programming is!
But have you ever wondered how exactly OOPs came into existence at all? Let's have a look.
History of OOPs
Terminology invoking "objects" and
"oriented" in the modern sense of object-oriented programming made
its first appearance at MIT in the late 1950s and early 1960s. In the
environment of the artificial intelligence group, as early as 1960,
"object" could refer to identified items with properties (attributes)
Another early MIT example was Sketchpad created by
Ivan Sutherland in 1960–61; in the glossary of the 1963 technical report based
on his dissertation about Sketchpad, Sutherland defined notions of "object"
and "instance" (with the class concept covered by "master"
or "definition"), albeit specialized to graphical interaction. Also,
an MIT ALGOL version, AED-0, established a direct link between data structures
and procedures, prefiguring what were later termed "messages",
"methods", and "member functions"
In the early and mid-1990s object-oriented
programming developed as the dominant programming paradigm when programming
languages supporting the techniques became widely available. These included Visual
FoxPro 3.0, C++ and Delphi. Its dominance was further enhanced by the rising
popularity of graphical user interfaces, which rely heavily upon
object-oriented programming techniques. An example of a closely related dynamic
GUI library and OOP language can be found in the Cocoa frameworks on Mac OS X,
written in Objective-C, an object-oriented, dynamic messaging extension to C
based on Smalltalk. OOP toolkits also enhanced the popularity of event-driven
programming (although this concept is not limited to OOP).
Let’s take a look at some of the facts about OOPs then?
Fact 1: Many people believe that OOP is a product of
the 1980s and the work done by Bjarne Stroustrup in moving the C language into
the object-oriented world by creating the C++ language. Actually, Simula 1
(1962) and Simula 67 (1967) are the two earliest object-oriented languages. The
work on the Simula languages was done by Ole-John Dahl and Kristen Nygaard at
the Norwegian Computing Center in Oslo, Norway. While most of the advantages of
OOP were available in the earlier Simula languages, it wasn't until C++ became
entrenched in the 1990s that OOP began to flourish.
Fact 2: C was the parent language of C++ and it was
often said that C was powerful enough to shoot yourself in the foot multiple
times. C++, on the other hand, not only was powerful enough to shoot yourself
in the foot, but you could blow your entire leg off without too much
difficulty. Most programmers admit that C++ is a very powerful language and it
is still in widespread use today. However, with that power comes a lot of
complexity. Language developers wanted a simpler and perhaps less complex
language for OOP development.
Fact 3: The development of OOP started in January of 1991 when James Gosling, Bill Joy, Patrick Naughton, Mike Sheradin, and several others met in Aspen, Colorado, to discuss ideas for the Stealth Project. The group wanted to develop intelligent electronic devices capable of being centrally controlled and programmed from a handheld device.
Fact 4: Alan Kay first coined the term “object-oriented programming” when he was attending a grad school.
Fact 5: The largest program ever written in human history is for Human Genome Project, where lines of code total up to 3300 billion.
Below is some graphical
representation of different programming language (2002-2018)
Now let us move ahead to grasp a knowledge of what makes Procedural Oriented Programming different from Object Oriented Programming
Procedural
Oriented Programming |
Object-Oriented Programming |
Procedural programming is based
upon top-down approach |
OOPs follows the bottom-up
approach |
In this paradigm function is
more important than data |
In this paradigm focus remains
on data rather than on functions |
From security perspective this
methodology suffers a bit because it does not have any proper way for
encapsulating data |
Whereas on other hand OOPs supports
abstraction and encapsulation that strengthens the data security |
In this concept the main
program is divided into various smaller parts based upon the functions and is
treated as separate entities for the standalone smaller program |
In OOPs concept of object and
class is introduced and hence the program is segregated into smaller chunks
called objects which are in turn instances of classes |
More sophisticated coding
approach |
Less complex coding technique |
Let's now take a look at some of the features of OOPs, shall we?
Features of OOPs
1. Insistence on data rather than
procedure
2. Programs are split up into smaller units called objects
3. Objects communicate with each other through further smaller
units called functions
4. Enhanced new functionality can be seamlessly developed by creating functions and objects
Do you know that OOPs is made up of some basic concepts that we can relate to in everyday life? Let’s have a look!
Concepts of OOPs
Abstraction – It is an act of representing only the “essential” details and “hide” the unnecessary background details or explanation. Let us take a few examples.
- Logging into the bank account online by entering your user id and password? But have you ever imagined what happens when you press the login button or how the data is sent to the server? Yes, you have got it right. Its all abstracted from you.
- Have you ever wondered what happens when you press a switch to turn on/off the lights or fans in your home or how the contact between the switch and the electrical equipment is established? Well, that is too abstracted from you.
Encapsulation – It is the process of wrapping up of data and functions into a single unit. Both Abstraction & Encapsulation work hand in hand because Abstraction says what details to be made visible and Encapsulation provides the level of access right to that visible details. Let us take a few examples.
- A capsule which is wrapped with different drug compositions exhibits the phenomenon of encapsulation.
- A working cell phone which
is constituted of various components exhibits encapsulation as well.
Inheritance – It is the feature wherein one class inherits or acquires the properties of another class hence promoting code reusability and achieving run-time polymorphism. Let us take an example.
- A software company has employees at various roles and responsibilities but the Employee base class contains the features common for all types/levels of employees and some properties that all employee must have for that company.
Polymorphism – It is the ability to take more than one
form such that an operation can exhibit different behaviour at different
instance depend upon the data passed in the operation. Let us take a few
examples.
- A person behaving differently in front of elders and friends.
- What about the stadium of commonwealth games? It is a single stadium but put forth to perform multiple tasks like swimming, lawn tennis, etc. Yes, it is also exhibiting polymorphism.
- If a girl is married, mother of 2 children and also doing teaching job then she is a women first, teacher in a school when she is in school, mother of her children, wife of someone, daughter of her parents.
Let me ask you a question. Do you know the
different languages that use these OOPs concepts?
Languages under OOPs
As we
know, OOP stands for Object Oriented Programming, is a design
philosophy. Object-Oriented Programming (OOP) uses a different set
of programming languages than old procedural programming languages (C, Pascal,
etc.). It is a computer programming model that organizes software design around
data, or objects, rather than functions and logic. Everything in OOP is grouped
as self-sustainable "objects". Hence, reader gain reusability by
means of four main object-oriented programming concepts.
OOP focuses on the objects that developers want to
manipulate rather than the logic required to manipulate them. An example of the
conventions in object-oriented programming has shown in Figure below,
What about various types of Object-Oriented Programming languages?
- Java
- C++
- JavaScript
- Python
- R
- PHP
These languages support object-oriented programming
to a greater or lesser degree, typically in combination with imperative,
procedural programming. Significant object-oriented languages include C#,
VisualBasic, .NET, JavaScript, Ruby, Perl, Object-Pascal, Objective-C, SQL, Swift,
Scala, Kotlin, Common Lisp, MATLAB, and Smalltalk. The main step in OOP is to
collect all the objects a programmer wants to manipulate and identify how they
relate to each other -- an exercise often known as Data modelling.
Overview of some popular Object-Oriented Programming languages
- Java has been one of the most popular
programming languages for many years. Java is Object Oriented. However, it is
not considered as pure object oriented as it provides support for primitive
data types (like int, char, etc). An object-based application in Java is based
on declaring classes, creating objects from them, and interacting between these
objects. Example of adding two numbers in Java programming language is shown
below.
- C++ is a middle-level programming
language. C++ is the most widely used programming languages in application and
system programming C++ is very close to hardware, so programmers can get a
chance to work at a low level which gives you lot of control in terms of memory
management, better performance and finally a robust software development.
Example of adding two numbers in C++ programming language is shown below.
- JavaScript is the world's most popular
programming language. JavaScript is the programming language of the Web. It is
designed for creating network-centric applications. It is complimentary to and
integrated with Java. JavaScript is very easy to implement because it is
integrated with HTML. It is open and cross-platform. Example of adding two
numbers in JavaScript programming language is shown below.
- Python is a high-level, general-purpose,
an interpreted language and a very popular programming language. The code can
be written once and run on almost any computer without needing to change the
program. Python programming language (latest Python 3) is being used in
web development, Machine Learning applications, along with all cutting-edge
technology in Software Industry. Example of adding two numbers (floating) in
Python programming language is shown below.
- R is a programming language and
software environment for statistical analysis, graphics representation and
reporting. R is freely available under the GNU General Public License, and
pre-compiled binary versions are provided for various operating systems like
Linux, Windows and Mac. R possesses an extensive catalog of statistical and
graphical methods. It includes machine learning algorithms, linear regression,
time series, statistical inference to name a few. Most of the R libraries are
written in R, but for heavy computational tasks, C, C++ and Fortran codes are
preferred. Example of comparing two numbers in R programming language is shown
below.
- PHP started out as a small open source
project that evolved as more and more people found out how useful it was. PHP
is a server scripting language, and a powerful tool for making dynamic and
interactive Web pages. PHP is a widely used, free, and efficient alternative to
competitors such as Microsoft's ASP. PHP is a recursive acronym for "PHP:
Hypertext Pre-processor”. It is integrated with several popular databases,
including MySQL, PostgreSQL, Oracle, Sybase, Informix, and Microsoft SQL
Server. Example of PHP program to calculate the sum of digits is shown below.
Online IDEs:
https://onecompiler.com/javascript
https://www.online-ide.com/online_java_editor
What are the advantages and
disadvantages of OOPS?
Advantages:
- Program is written as a different function and modulus that interact with each other. It is a function-driven language.
- Size of the Non-Procedural language programs are small.
- Execution time is very fast.
- It is suitable for time critical applications.
- Code becomes cleaner and easy to understand.
Disadvantages:
- Overall efficiency is low as compared to Procedural Language.
- The syntax of this language is not very easy.
References:
Wonderful!
Hope you like this blog. Stay tuned for our upcoming blog.. 🤞😊