KEMBAR78
Introduction to object oriented programming.pptx
WHAT IS
COMPUTER
PROGRAMMING?
1.0 WHAT IS COMPUTER PROGRAMMING?
• Today, most people don't need to know how a computer
works.
• Most people can simply turn on a computer or a mobile
phone and point at some little graphical object on the
display, click a button or swipe a finger or two, and the
computer does something.
• An example would be to get weather information from
the net and display it.
• How to interact with a computer program is all the
average person needs to know.
• But, since you are going to learn how to write computer
programs, you need to know a little bit about how a
1.0 WHAT IS COMPUTER PROGRAMMING? …
• Now before we understand what programming is, you
must know what is a computer.
• A computer is a device that can accept human
instruction, processes it and responds to it or a computer
is a computational device which is used to process the
data under the control of a computer program.
• Program is a sequence of instruction along with data.
• The basic components of a computer are:
• Input unit
• Central Processing Unit(CPU)
• Output unit
1.0 WHAT IS COMPUTER PROGRAMMING? …
• The CPU is further divided into three parts-
• Memory unit
• Control unit
• Arithmetic Logic unit
• Most of us have heard that CPU is called the brain of our
computer because it accepts data, provides temporary memory
space to it until it is stored(saved) on the hard disk, performs
logical operations on it and hence processes(here also means
converts) data into information.
• We all know that a computer consists of hardware (H/W) and
software (S/W).
• Software (S/W) is a set of programs that performs multiple tasks
together.
• An operating system is also a software (system software) that
1.1 INTRODUCTION TO COMPUTER PROGRAMMING?
• A program is a set of instructions given to a computer to
perform a specific operation.
• or computer is a computational device which is used to
process the data under the control of a computer program.
• While executing the program, raw data is processed into
a desired output format.
• These computer programs are written in a programming
language which are high level languages.
• High level languages are nearly human languages which
are more complex than the computer understandable
language which are called machine (m/c) language, or
low level.
1.1 INTRODUCTION TO COMPUTER PROGRAMMING? …
• So after knowing the basics, we are ready to
create a very simple and basic program.
• Like we have different languages to
communicate with each other, likewise, we have
different languages like C, C++, C#, Java,
python, etc. to communicate with the computers.
• The computer only understands binary language
(the language of 0’s and 1’s) also called machine-
understandable language or low-level language
but the programs we are going to write are in a
high-level language which is almost similar to
1.1 INTRODUCTION TO COMPUTER PROGRAMMING? …
• Before getting into computer programming, let
us first understand computer programs and
what they do.
• A computer program is a sequence of
instructions written using a Computer
Programming Language to perform a specified
task by the computer.
• The two important terms that we have used in
the above definition are −
• Sequence of instructions
1.1 INTRODUCTION TO COMPUTER PROGRAMMING? …
• To understand these terms, consider a situation when
someone asks you about how to go to a nearby
HOTEL.
• What exactly do you do to tell him the way to go to
HOTEL?
• You will use Human Language to tell the way to go to
HOTEL, something as follows −
First go straight, after half kilometer, take left
from the red light and then drive around one
kilometer and you will find HOTEL at the
right.
1.1 INTRODUCTION TO COMPUTER PROGRAMMING? …
• Here, you have used English Language to give several
steps to be taken to reach HOTEL.
• If they are followed in the following sequence, then
you will reach HOTEL −
STEP 1: Go straight
STEP 2: Drive half kilometer
STEP 3: Take left
STEP 4: Drive around one kilometer
STEP 5: Search for HOTEL at your right side
1.1 INTRODUCTION TO COMPUTER PROGRAMMING? …
• Now, try to map the situation with a computer
program.
The above sequence of instructions is actually
a Human Program written in English
Language, which instructs on how to reach
HOTEL from a given starting point.
This same sequence could have been given in
Spanish, Hindi, Arabic, or any other human
language, provided the person seeking
direction knows any of these languages.
1.1 INTRODUCTION TO COMPUTER PROGRAMMING? …
• Now, let's go back and try to understand a computer
program, which is a sequence of instructions written in a
Computer Language to perform a specified task by the
computer.
• Following is a simple program written in Python programming
Language −
• The above computer program instructs the computer to print
"Hello, World!" on the computer screen.
 A computer program is also called a computer software, which can range from two
lines to millions of lines of instructions.
 Computer program instructions are also called program source code and computer
programming is also called program coding.
 A computer without a computer program is just a dump box; it is programs that
make computers active.
print "Hello, World!"
1.1 INTRODUCTION TO COMPUTER PROGRAMMING? …
• As we have developed so many
languages to communicate among
ourselves, computer scientists have
developed several computer-
programming languages to provide
instructions to the computer (i.e., to
write computer programs).
1.1 INTRODUCTION TO COMPUTER PROGRAMMING? …
• The piece of code given below performs a basic task
of printing “Hello, World!” on the console screen.
• We must know that keyboard, scanner, mouse,
microphone, etc. are various examples of input
devices and monitor(console screen), printer,
speaker, etc. are the examples of output devices.
main()
{
clrscr();
printf(“Hello, World!");
getch();
}
1.1 INTRODUCTION TO COMPUTER PROGRAMMING? …
• At this stage, you might not be able to understand in-
depth how this code prints something on the screen.
• The main() is a standard function that you will always
include in any program that you are going to create from
now onwards.
• Note that the execution of the program starts from the
main() function.
• The clrscr() function is used to see only the current
output on the screen while the printf () function helps us
to print the desired output on the screen.
• Also, getch() is a function that accepts any character
input from the keyboard.
• In simple words, we need to press any key to
1.1 INTRODUCTION TO COMPUTER PROGRAMMING? …
• Between high-level language and machine
language there are assembly language also
called symbolic machine code.
• Assembly language are particularly computer
architecture specific.
• Utility program (Assembler) is used to convert
assembly code into executable machine code.
• High Level Programming Language are
portable but require Interpretation or compiling
to convert it into a machine language which is
1.1 INTRODUCTION TO COMPUTER PROGRAMMING? …
• If you understood what a computer program is, then we will
say: the act of writing computer programs is called computer
programming.
• As we mentioned earlier, there are hundreds of programming
languages, which can be used to write computer programs
and following are a few of them −
• Java
• C
• C++
• Python
• PHP
• Perl
• Ruby
1.2 USES OF COMPUTER PROGRAMS
• Today computer programs are being used in almost every
field, household, agriculture, medical, entertainment,
defense, communication, etc.
• Listed below are a few applications of computer
programs −
MS Word, MS Excel, Adobe Photoshop, Internet Explorer,
Chrome, etc., are examples of computer programs.
Computer programs are being used to develop graphics
and special effects in movie making.
Computer programs are being used to perform
Ultrasounds, X-Rays, and other medical examinations.
Computer programs are being used in our mobile phones
1.4 COMPUTER PROGRAMMER
• Someone who can write computer programs or in other
words, someone who can do computer programming is called
a Computer Programmer.
• Based on computer programming language expertise, we can
name a computer programmers as follows −
C Programmer
C++ Programmer
Java Programmer
Python Programmer
PHP Programmer
Perl Programmer
Ruby Programmer
1.5 ALGORITHM
• From programming point of view, an
algorithm is a step-by-step procedure to
resolve any problem.
• An algorithm is an effective method
expressed as a finite set of well-defined
instructions.
• Thus, a computer programmer lists down
all the steps required to resolve a problem
before writing the actual code.
1.5 ALGORITHM …
• Following is a simple example of an algorithm to find out the
largest number from a given list of numbers −
• The above algorithm has been written in a crude way to help
beginners understand the concept.
• You will come across more standardized ways of writing
computer algorithms as you move on to advanced levels of
1. Get a list of numbers L1, L2, L3....LN
2. Assume L1 is the largest, Largest = L1
3. Take next number Li from the list and do the following
4. If Largest is less than Li
5. Largest = Li
6. If Li is last number from the list then
7. Print value stored in Largest and come out
8. Else repeat same process starting from step 3
1.6 HIERARCHY OF COMPUTER LANGUAGE
1.6 HIERARCHY OF COMPUTER LANGUAGE …
• There have
been many
programming
language some
of them are
listed below:
C Python C++
C# R Ruby
COBOL ADA Java
Fortran BASIC Altair BASIC
True BASIC Visual BASIC GW BASIC
QBASIC PureBASIC PASCAL
Turbo Pascal GO ALGOL
LISP SCALA Swift
Rust Prolog Reia
Racket Scheme Shimula
Perl PHP Java Script
CoffeeScript VisualFoxPro Babel
Logo Lua Smalltalk
Matlab F F#
Dart Datalog dbase
Haskell dylan Julia
ksh metro Mumps
Nim OCaml pick
TCL D CPL
Curry ActionScript Erlang
Clojure DarkBASCIC Assembly
1.6 HIERARCHY OF COMPUTER LANGUAGE …
• Most Popular Programming Languages –
C
Python
C++
Java
SCALA
C#
R
Ruby
Go
Swift
JavaScript
1.7 CHARACTERISTICS OF COMPUTER LANGUAGE …
A programming language must be simple, easy to learn and use, have
good readability and human recognizable.
Abstraction is a must-have Characteristics for a programming language
in which ability to define the complex structure and then its degree of
usability comes.
A portable programming language is always preferred.
Programming language’s efficiency must be high so that it can be easily
converted into a machine code and executed consumes little space in
memory.
A programming language should be well structured and documented so
that it is suitable for application development.
Necessary tools for development, debugging, testing, maintenance of a
program must be provided by a programming language.
A programming language should provide single environment known as
Integrated Development Environment(IDE).

2.0 WHAT IS OBJECT ORIENTED PROGRAMMING (OOP) ?
• Object Oriented programming (OOP) is a
programming paradigm that includes or relies
on the concept of classes and objects.
• It is used to structure a software program into
simple, reusable pieces of code blueprints
(usually called classes) which are used to create
individual instances of objects.
• Because OOP is a programming paradigm,
there are many object-oriented programming
languages including: C++, Java, and Python.
• A programmer designs a software program
by organizing related pieces of information
and behaviors together into a template
called a class.
• Then individual objects are instantiated or
created from the class template; these
objects usually represent a real world
thing.
• The entire software program runs by
having multiple objects interact with
2.0 WHAT IS OBJECT ORIENTED PROGRAMMING (OOP) ? …
2.1 WHY OOP?
• OOP makes code organized, reusable, and easy
to maintain; It follows the DRY method (Don’t
Repeat Yourself).
• Benefits of OOP include security; OOP prevents
unwanted access to data, or exposing
proprietary code through encapsulation and
abstraction - both are discussed further in the
Principles of OOP section.
• So how do programmers create Object Oriented
programs? Well the short answer is by making
classes, and creating objects from the classes.
2.1 WHY OOP? …
• In OOP everything is an object.
• Classes form the blueprint for how data &
behaviors are structured.
• Objects are created for specific instances of a
class.
• As a programmer, you might create a dog class
(blueprint) as a standard way to organize all the
important information about dogs, and then
instantiate an individual dog as an object
created from the dog class - like your dog
Fluffy.
2.2 BUILDING BLOCKS OF OOP
• The code building blocks to build
an OOP program we’ll discuss
are:
classes
objects
methods
attributes
2.3 EXAMPLE OOP STRUCTURE
• Let’s take a real world problem, and
conceptually design an OOP software
program.
• Imagine running a pet sitting camp, with
hundreds of pets, and you have to keep
track of the names, ages, and days
attended for each pet.
• How would you design simple, reusable
software to model the pets?
2.3 EXAMPLE OOP STRUCTURE
• In the pet sitting camp example, here’s how a programmer could think
about organizing an OOP:
1) Group pets into categories Like Dog, Cat
• Determine the information the software should model for each pet category
2) Create classes
• Classes a blueprint of information for each pet
3) Add Attributes to classes
• Data fields to store for each pet, like name
4) Add Behaviors to classes
• Functionality that each pet needs to do, like bark
5) Create objects from the class
• Objects are individual instances of the class template
• In our case dogs like Rufus & Fluffy
2.4 AN OBJECT-ORIENTED CLASS
• If we think of a real-world object, such as a television
it will have several features and properties:
We do not have to open the case to use it.
We have some controls to use it (buttons on the box, or a
remote control).
We can still understand the concept of a television, even if
it is connected to a DVD player.
It is complete when we purchase it, with any external
requirements well documented.
The TV will not crash!
• In many ways this compares very well to the notion of
a class
2.4.1 THE CONCEPT OF A CLASS- TELEVISION EXAMPLE
2.4.1 THE CONCEPT OF A CLASS- TELEVISION EXAMPLE …
• A class should:
Provide a well-defined interface - such as the
remote control of the television.
Represent a clear concept - such as the concept of
a television.
Be complete and well-documented - the television
should have a plug and should have a manual that
documents all features.
The code should be robust - it should not crash,
like the television.
2.4.2 A CLASS
• With a functional programming language (like C) we would
have the component parts of the television scattered
everywhere and we would be responsible for making them
work correctly - there would be no case surrounding the
electronic components.
• Humans use class based descriptions all the time - what is a
duck?
• Classes allow us a way to represent complex structures within
a programming language.
• They have two components:
States - (or data) are the values that the object has.
Methods - (or behaviour) are the ways in which the object can
interact with its data, the actions.
2.4.3 THE TELEVISION CLASS EXAMPLE
• An instance of a class is called an object.
2.5 AN OBJECT
• An object is an instance of a class.
• You could think of a class as the description of a
concept, and an object as the realization of this
description to create an independent
distinguishable entity.
• For example, in the case of the Television, the
class is the set of plans (or blueprints) for a
generic television, whereas a television object is
the realization of these plans into a real-world
physical television.
• So there would be one set of plans (the class),
but there could be thousands of real-world
2.5 AN OBJECT …
• Objects can be concrete (a real-world object, a
file on a computer) or could be conceptual
(such as a database structure) each with its
own individual identity.
• Figure shows an example where the Television
class description is realized into several
television objects.
• These objects should have their own identity
and are independent from each other.
• For example, if the channel is changed on one
television it will not change on the other
2.5.1 THE TELEVISION OBJECTS EXAMPLE
2.5.2 THE HOUSE OBJECTS EXAMPLE
• A class is a blueprint for creating an object.
• It is similar to the blue print of a house.
2.5.3 THE PARROT OBJECTS EXAMPLE
• One of the popular approaches to solve a programming
problem is by creating objects.
• This is known as Object-Oriented Programming (OOP).
• An object has two characteristics:
attributes
behavior
• Let's take an example:
• A parrot is can be an object, as it has the following properties:
name, age, color as attributes
singing, dancing as behavior
• The concept of OOP in programming focuses on creating
reusable code.
2.5.3 THE PARROT OBJECTS EXAMPLE : CLASS
• A class is a blueprint for the object.
• We can think of class as a sketch of a parrot with
labels.
• It contains all the details about the name, colors, size etc.
• Based on these descriptions, we can study about the
parrot.
• Here, a parrot is an object.
• The example for class of parrot can be :
• Here, we use the class keyword to define an empty
class Parrot.
• From class, we construct instances.
class Parrot:
pass
2.5.3 THE PARROT OBJECTS EXAMPLE : OBJECT
• An object (instance) is an instantiation of a
class.
• When class is defined, only the description for the
object is defined.
• Therefore, no memory or storage is allocated.
• The example for object of parrot class can be:
• Here, obj is an object of class Parrot.
obj = Parrot()
2.5.4 THE FRUIT OBJECTS EXAMPLE
2.5.5 THE CAR OBJECTS EXAMPLE
• So, a class is a template for objects, and an object is an
instance of a class.
• When the individual objects are created, they inherit all
the variables and functions from the class.
3.0 OBJECT ORIENTED PROGRAMMING (OOPS) CONCEPT
• As the name suggests, Object-Oriented
Programming or OOPs refers to languages that
uses objects in programming.
• Object-oriented programming aims to
implement real-world entities like inheritance,
hiding, polymorphism etc. in programming.
• The main aim of OOP is to bind together the
data and the functions that operate on them so
that no other part of the code can access this
data except that function.
3.0 OBJECT ORIENTED PROGRAMMING (OOPS) CONCEPT …
3.0 OBJECT ORIENTED PROGRAMMING (OOPS) CONCEPT …
• OOPs Concepts:
Class
Object
Polymorphism
Inheritance
Encapsulation
Abstraction
Method
Message Passing
3.1 OBJECT ORIENTED PROGRAMMING (OOPS) CONCEPT : ENCAPSULATION
• Say we have a program.
• It has a few logically different objects which
communicate with each other — according to
the rules defined in the program.
• Encapsulation is achieved when each object
keeps its state private, inside a class.
• Other objects don’t have direct access to this
state.
• Instead, they can only call a list of public functions
— called methods.
3.1 OBJECT ORIENTED PROGRAMMING (OOPS) CONCEPT : ENCAPSULATION …
• So, the object manages its own state via
methods — and no other class can touch it
unless explicitly allowed.
• If you want to communicate with the object,
you should use the methods provided.
• But (by default), you can’t change the state.
3.1 OBJECT ORIENTED PROGRAMMING (OOPS) CONCEPT : ENCAPSULATION …
• Let’s say we’re building a tiny Sims
game.
• There are people and there is a cat.
• They communicate with each other.
• We want to apply encapsulation, so we
encapsulate all “cat” logic into a Cat
class.
• It may look like this:
3.1 OBJECT ORIENTED PROGRAMMING (OOPS) CONCEPT : ENCAPSULATION …
• You can feed the cat.
• But you can’t directly change how hungry the cat is.
3.1 OBJECT ORIENTED PROGRAMMING (OOPS) CONCEPT : ENCAPSULATION …
• Here the “state” of the cat is the private variables mood,
hungry and energy.
• It also has a private method meow().
• It can call it whenever it wants, the other classes can’t tell
the cat when to meow.
• What they can do is defined in the public methods sleep(),
play() and feed().
• Each of them modifies the internal state somehow and may
invoke meow().
• Thus, the binding between the private state and public
methods is made.
• This is encapsulation.
3.1 WHAT IS ENCAPSULATION? (DEFINITION 1)
• In object-oriented computer programming
languages, the notion of encapsulation refers to
the bundling of data, along with the methods that
operate on that data, into a single unit.
• Many programming languages use encapsulation
frequently in the form of classes.
• A class is a program-code-template that allows
developers to create an object that has both
variables (data) and behaviors (functions or
methods).
• A class is an example of encapsulation in that it
consists of data and methods that have been
3.1 WHAT IS ENCAPSULATION? (DEFINITION 1)…
• Encapsulation may also refer to a
mechanism of restricting the direct access
to some components of an object, such that
users cannot access state values for all of
the variables of a particular object.
• Encapsulation can be used to hide both
data members and data functions or
methods associated with an instantiated
class or object.
3.1 WHAT IS ENCAPSULATION? (DEFINITION 2)
• Encapsulation is one of the fundamental concepts in object-
oriented programming (OOP).
• It describes the idea of bundling data and methods that work
on that data within one unit, e.g., a class in Java.
• This concept is also often used to hide the internal representation, or
state, of an object from the outside.
• This is called information hiding.
• The general idea of this mechanism is simple.
• If you have an attribute that is not visible from the outside of
an object, and bundle it with methods that provide read or
write access to it, then you can hide specific information and
control access to the internal state of the object.
3.1 WHAT IS ENCAPSULATION? (DEFINITION 2) …
• If you’re familiar with any object-oriented
programming language, you probably know
that these methods as getter and setter
methods.
• As the names indicate, a getter method
retrieves an attribute, and a setter method
changes it.
• Depending on the methods that you
implement, you can decide if an attribute
can be read and changed, or if it’s read-
3.1 WHAT IS ENCAPSULATION? (DEFINITION 3)
• In normal terms Encapsulation is defined as wrapping up of
data and information under a single unit.
• In Object Oriented Programming, Encapsulation is defined as
binding together the data and the functions that manipulates
them.
• Consider a real life example of encapsulation, in a company
there are different sections like the accounts section, finance
section, sales section etc.
• The finance section handles all the financial transactions and
keep records of all the data related to finance.
• Similarly the sales section handles all the sales related
activities and keep records of all the sales.
• Now there may arise a situation when for some reason an
official from finance section needs all the data about sales in a
3.1 WHAT IS ENCAPSULATION? (DEFINITION 3) …
• In this case, he is not allowed to directly access the data of sales
section.
• He will first have to contact some other officer in the sales section
and then request him to give the particular data.
• This is what encapsulation is.
• Here the data of sales section and the employees that can manipulate
them are wrapped under a single name “sales section”.
• Encapsulation also lead to data abstraction or hiding.
• As using encapsulation also hides the data.
• In the above example the data of any of the section like sales, finance
or accounts is hidden from any other section.
3.1 WHAT IS ENCAPSULATION? (DEFINITION 4)
• Encapsulation is:
Binding the data with the code that manipulates it.
It keeps the data and the code safe from external interference
• Looking at the example of a power steering mechanism of a
car.
• Power steering of a car is a complex system, which internally
have lots of components tightly coupled together, they work
synchronously to turn the car in the desired direction.
• It even controls the power delivered by the engine to the
steering wheel.
• But to the external world there is only one interface is available
and rest of the complexity is hidden.
• Moreover, the steering unit in itself is complete and
independent.
3.1 WHAT IS ENCAPSULATION? (DEFINITION 4) …
• Similarly, same concept of encapsulation can be
applied to code.
• Encapsulated code should have following
characteristics:
Everyone knows how to access it.
Can be easily used regardless of implementation
details.
There shouldn’t any side effects of the code, to
the rest of the application.
• The idea of encapsulation is to keep classes
separated and prevent them from having tightly
3.2 REAL-TIME EXAMPLE OF ENCAPSULATION
Real-time Example 1:
• School bag is one of the most real examples of Encapsulation.
• School bag can keep our books, pens, etc.
Real-time Example 2:
• When you log into your email accounts such as Gmail, Yahoo Mail,
or Rediff mail, there is a lot of internal processes taking place in
the backend and you have no control over it.
• When you enter the password for logging, they are retrieved in an
encrypted form and verified, and then you are given access to
your account.
• You do not have control over it that how the password has been
verified.
3.2 REAL-TIME EXAMPLE OF ENCAPSULATION …
Real-time Example 3:
• Suppose you have an account in the bank.
• If your balance variable is declared as a public variable in the bank
software, your account balance will be known as public, In this case,
anyone can know your account balance.
• So, would you like it? Obviously No.
• So, they declare balance variable as private for making your account
safe, so that anyone cannot see your account balance.
• The person who has to see his account balance, will have to access only
private members through methods defined inside that class and this method
will ask your account holder name or user Id, and password for
authentication.
• Thus, we can achieve security by utilizing the concept of data hiding.
This is called Encapsulation.
3.2 REAL-TIME EXAMPLE OF ENCAPSULATION
Real-time Example 4:
• The interaction between a user and a mobile
phone.
• The user does not need to know the internal
working of the mobile phone to operate, so this
is called abstraction.
• Encapsulation is a way to achieve "information
hiding" so, following your example, you don't
"need to know the internal working of the
mobile phone to operate" with it.
• You have an interface to use the device
behaviour without knowing implementation
4.0 WHAT IS ABSTRACTION?
• Abstraction is the process of hiding the
internal details of an application from the
outer world.
• Abstraction is used to describe things in
simple terms.
• It’s used to create a boundary between the
application and the client programs.
4.1 ABSTRACTION IN REAL LIFE
• Abstraction is present in almost all the real life machines.
Your car is a great example of abstraction.
• You can start a car by turning the key or pressing the start
button.
• You don’t need to know how the engine is getting started, what
all components your car has.
• The car internal implementation and complex logic is
completely hidden from the user.
We can heat our food in Microwave.
• We press some buttons to set the timer and type of food.
• Finally, we get a hot and delicious meal.
• The microwave internal details are hidden from us.
• We have been given access to the functionality in a very simple
4.1 ABSTRACTION IN REAL LIFE …
• Data abstraction refers to providing only essential
information to the outside world and hiding their
background details, i.e., to represent the needed
information in program without presenting the details.
• Data abstraction is a programming (and design)
technique that relies on the separation of interface and
implementation.
• Let's take one real life example of a TV, which you can
turn on and off, change the channel, adjust the volume,
and add external components such as speakers, VCRs,
and DVD players, BUT you do not know its internal
details, that is, you do not know how it receives signals
over the air or through a cable, how it translates them,
4.1 ABSTRACTION IN REAL LIFE …
• Thus, we can say a television clearly separates its
internal implementation from its external interface and
you can play with its interfaces like the power button,
channel changer, and volume control without having
any knowledge of its internals.
• Abstraction is a programming methodology in which
details of the programming codes are hidden away from
the user, and only the essential things are displayed to
the user.
• Abstraction is concerned with ideas rather than events.
• It’s like a user running a program (Web Browser)
4.1 ABSTRACTION IN REAL LIFE …
• I’m a coffee addict.
• So, when I wake up in the morning, I go into my kitchen, switch on the coffee machine
and make coffee.
• Sounds familiar?
• Making coffee with a coffee machine is a good example of abstraction.
• You need to know how to use your coffee machine to make coffee.
• You need to provide water and coffee beans, switch it on and select the kind of coffee
you want to get.
• The thing you don’t need to know is how the coffee machine is working internally to
brew a fresh cup of delicious coffee.
• You don’t need to know the ideal temperature of the water or the amount of ground
coffee you need to use.
• Someone else worried about that and created a coffee machine that now acts as an
abstraction and hides all these details.
• You just interact with a simple interface that doesn’t require any knowledge about the
internal implementation.
4.2 ABSTRACTION IN OOPS
• ABSTRACTION is the concept of object-oriented
programming that "shows" only essential
attributes and "hides" unnecessary information.
• The main purpose of abstraction is hiding the
unnecessary details from the users.
• Abstraction is selecting data from a larger pool
to show only relevant details of the object to the
user.
• It helps in reducing programming complexity
and efforts.
• It is one of the most important concepts of
4.3 LET'S STUDY ABSTRACTION CONCEPT WITH AN EXAMPLE
• Suppose you want to
create a banking
application and you are
asked to collect all the
information about your
customer.
• There are chances that
you will come up with
following information
about the customer.
4.3 LET'S STUDY ABSTRACTION CONCEPT WITH AN EXAMPLE …
• But, not all of the above information is required to
create a banking application.
• So, you need to select only the useful information for
your banking application from that pool.
• Data like name, address, tax information, etc. make
sense for a banking application.
4.3 LET'S STUDY ABSTRACTION CONCEPT WITH AN EXAMPLE …
• Since we have fetched/removed/selected the
customer information from a larger pool, the process
is referred as Abstraction.
• However, the same information once extracted can be
used for a wide range of applications.
• For instance, you can use the same data for hospital
application, job portal application, a Government
database, etc. with little or no modification.
• Hence, it becomes your Master Data.
• This is an advantage of Abstraction.
4.4 WHAT ARE THE DIFFERENT TYPES OF ABSTRACTION
There are two types of abstraction.
1) Data Abstraction
2) Process Abstraction
4.4 WHAT ARE THE DIFFERENT TYPES OF ABSTRACTION : 1) DATA ABSTRACTION
o When the object data
is not visible to the
outer world, it
creates data
abstraction.
o If needed, access to
the Objects’ data is
provided through
some methods.
4.4 WHAT ARE THE DIFFERENT TYPES OF ABSTRACTION : 2) PROCESS ABSTRACTION
 We don’t need to
provide details about
all the functions of
an object.
 When we hide the
internal
implementation of
the different
functions involved in
a user operation, it
creates process
abstraction.
4.5 ADVANTAGES OF ABSTRACTION
The main benefit of using an abstract class is that it
allows you to group several related classes as
siblings.
Abstraction helps to reduce the complexity of the
design and implementation process of software.
Another advantage of using this feature is that when
the code evolves and you need to make some
adjustments in the code then you only need to modify
the high level class where you have declared the
members as private.
Since none class is accessing these data members
directly, you do not need to change the low level(user
4.5 ADVANTAGES OF ABSTRACTION …
Imagine if you had made these data members
public, if at some point you want to change the
code, you would have to make the necessary
adjustments to all the classes that are accessing
the members directly.
Makes the application secure by making data
private and avoiding the user level error that
may corrupt the data.
This avoids code duplication and increases the
4.6 DIFFERENCE B/W ABSTRACTION AND ENCAPSULATION
Abstraction Encapsulation
 Abstraction solves the issues at
the design level.
 Encapsulation solves it
implementation level.
 Abstraction is about hiding
unwanted details while showing
most essential information.
 Encapsulation means binding
the code and data into a single
unit.
 Abstraction allows focussing on
what the information object
must contain
 Encapsulation means hiding the
internal details or mechanics of
how an object does something
for security reasons.
5.0 WHAT IS POLYMORPHISM ?
• The word polymorphism means having many
forms.
• In simple words, we can define polymorphism
as the ability of a message to be displayed in
more than one form.
5.0 WHAT IS POLYMORPHISM ? …
• The word polymorphism is used in various
contexts and describes situations in which
something occurs in several different forms.
• In computer science, it describes the concept
that objects of different types can be accessed
through the same interface.
• Each type can provide its own, independent
implementation of this interface.
• It is one of the core concepts of object-oriented
programming (OOP).
5.0 WHAT IS POLYMORPHISM ? …
• If you’re wondering if an object is polymorphic,
you can perform a simple test.
• If the object successfully passes multiple is-a or
instanceof tests, it’s polymorphic.
• As I’ve described in my post about inheritance,
all Java classes extend the class Object.
• Due to this, all objects in Java are polymorphic
because they pass at least two instanceof
checks.
5.1 REAL LIFE EXAMPLE OF POLYMORPHISM:
• A person at the same time can have different
characteristic.
• Like a man at the same time is a father, a husband, an
employee.
• So the same person posses different behaviour in different
situations. This is called polymorphism.
• Polymorphism is considered as one of the important
features of Object Oriented Programming.
• Polymorphism allows us to perform a single action in
different ways.
• In other words, polymorphism allows you to define one
interface and have multiple implementations.
• The word “poly” means many and “morphs” means forms,
5.1 REAL LIFE EXAMPLE OF POLYMORPHISM …
• Polymorphism is one of the OOPs feature
that allows us to perform a single action in
different ways.
• For example, lets say we have a class
Animal that has a method sound().
• Since this is a generic class so we can’t
give it a implementation like: the lions
roars, the pig oinks, and the cat meows,
etc.
5.1 REAL LIFE EXAMPLE OF POLYMORPHISM …
• Suppose if you are in
class room that time you
behave like a student,
when you are in market
at that time you behave
like a customer, when
you at your home at that
time you behave like a
son or daughter, Here
one person present in
different-different
behaviors.
5.1 REAL LIFE EXAMPLE OF POLYMORPHISM …
• You can see in the below
Images, you can see, Man
is only one, but he takes
multiple roles like - he is a
dad to his child, he is an
employee, a salesperson
and many more.
• This is known as
Polymorphism.
5.1 REAL LIFE EXAMPLE OF POLYMORPHISM …
• In today’s world, everything that we
imagined in the past is becoming a
reality.
• Be it from the Sci-fi movies or our
imagination and ideas, we have worked
towards turning them into reality.
• Similarly, programs (computer and
programming languages) were designed
to solve problems faster and with
accuracy.
• So, it is very crucial to understand
programming concepts with real-life
examples and context.
5.1 REAL LIFE EXAMPLE OF POLYMORPHISM …
• Today, we will learn How Polymorphism is connected to the
real world?
• Below we have a conversation between the Real World and
Polymorphism.
• Let’s have a look at the conversation.
• Real World: Hye Poly! why you look so sad?
• Polymorphism: Nothing dude, I am missing you a lot.
• Real World: Thank you, buddy.
• Even I miss you a lot. But don’t you think we are always
5.2 POLYMORPHISM IN OOPS
• The word polymorphism is used in various contexts and
describes situations in which something occurs in several
different forms.
• In computer science, it describes the concept that objects
of different types can be accessed through the same
interface.
• Each type can provide its own, independent
implementation of this interface.
• It is one of the core concepts of object-oriented
programming (OOP).
• If you’re wondering if an object is polymorphic, you can
perform a simple test.
• If the object successfully passes multiple is-a or
5.2 POLYMORPHISM IN OOPS …
• Polymorphism in programming languages occurs when there
are one or more classes or objects related to each other by
inheritance.
• In other words, it is the ability of an object to take many forms.
• Inheritance lets users inherit attributes and methods, and
polymorphism uses these methods for performing different
tasks.
• So, the goal is communication but the approach is different.
• For example, you have a smartphone for communication.
• The communication mode you choose could be anything.
• It can be a call, a text message, a picture message, mail, etc.
• So, the goal is common that is communication, but their
approach is different.
5.3 POLYMORPHISM IN OOP’S WITH EXAMPLE
• We have one parent class, ‘Account’ with function of deposit
and withdraw.
• Account has 2 child classes.
• The operation of deposit and withdraw is same for Saving and
Checking accounts.
• So the inherited methods from Account class will work.
5.3 POLYMORPHISM IN OOP’S WITH EXAMPLE…
• Change in Software Requirement
• There is a change in the requirement specification,
something that is so common in the software industry.
• You are supposed to add functionality privileged Banking
Account with Overdraft Facility.
• For a background, overdraft is a facility where you can
withdraw an amount more than available the balance in
your account.
• So, withdraw method for privileged needs to implemented
afresh.
• But you do not change the tested piece of code in Savings
and Checking account.
5.3 POLYMORPHISM IN OOP’S WITH EXAMPLE…
93
5.3 POLYMORPHISM IN OOP’S WITH EXAMPLE…
Step 1 :
• Such that when the
"withdrawn" method
for saving account is
called a method
from parent account
class is executed.
5.3 POLYMORPHISM IN OOP’S WITH EXAMPLE…
Step 2 :
• But when the "Withdraw" method for the privileged
account (overdraft facility) is called withdraw method
defined in the privileged class is executed.
• This is Polymorphism.
5.3 POLYMORPHISM IN OOP’S WITH EXAMPLE…
• Polymorphism has been derived from a
biological term that means ability of an
organism to adopt multiple forms.
• In OOPs, polymorphism refers to the ability of
referring and processing multiple objects and
classes through a unified interface.
• Any object that satisfies multiple IS-A
relationships is a candidate of being
implemented as a polymorphic object.
5.3 POLYMORPHISM IN OOP’S WITH EXAMPLE…
• For instance, the object of class Square IS-A Square;
It IS-A Shape as well and It IS-An object as well.
• It means that Object and Shape can be declared
parent classes of child Square classes.
• Therefore, a common interface Object can be used to
refer to all objects of Square class.
• Also, Shape interface can also be used to refer to all
objects of Square class and so on.
• This is due to the IS-A relationship of Square with
Object and Shape classes.
6.0 WHAT IS INHERITANCE IN OOPS?
• Inheritance is one of the core concepts of object-oriented
programming (OOP) languages.
• It is a mechanism where you can to derive a class from
another class for a hierarchy of classes that share a set of
attributes and methods.
• Inheritance is a mechanism in which one class acquires
the property of another class.
• For example, a child inherits the traits of his/her parents.
• With inheritance, we can reuse the fields and methods of
the existing class.
• Hence, inheritance facilitates Reusability and is an
important concept of OOPs.
6.0 WHAT IS INHERITANCE IN OOPS? …
• One of the most important concepts in object-oriented
programming is that of inheritance.
• Inheritance allows us to define a class in terms of another
class, which makes it easier to create and maintain an
application.
• This also provides an opportunity to reuse the code
functionality and fast implementation time.
• When creating a class, instead of writing completely new
data members and member functions, the programmer
can designate that the new class should inherit the
members of an existing class.
• This existing class is called the base class, and the new
6.0 WHAT IS INHERITANCE IN OOPS? …
• One of the most important concepts in object-oriented
programming is that of inheritance.
• Inheritance allows us to define a class in terms of another class,
which makes it easier to create and maintain an application.
• This also provides an opportunity to reuse the code functionality and
fast implementation time.
• When creating a class, instead of writing completely new data
members and member functions, the programmer can
designate that the new class should inherit the members of an
existing class.
• This existing class is called the base class, and the new class is
referred to as the derived class.
• The idea of inheritance implements the is a relationship.
• For example, mammal IS-A animal, dog IS-A mammal hence dog IS-A
6.0 WHAT IS INHERITANCE IN OOPS? …
• Inheritance is one of the feature of Object Oriented
Programming System(OOPs), it allows the child class to
acquire the properties (the data members) and
functionality (the member functions) of parent class.
What is child class?
• A class that inherits another class is known as child class,
it is also known as derived class or subclass.
What is parent class?
• The class that is being inherited by other class is known
as parent class, super class or base class.
6.1 WHAT ARE THE ADVANTAGES OF USING INHERITANCE
• The main advantages of inheritance are
code reusability and readability.
• When child class inherits the properties
and functionality of parent class, we need
not to write the same code again in child
class.
• This makes it easier to reuse the code,
makes us write the less code and the code
becomes much more readable.
6.1 WHAT ARE THE ADVANTAGES OF USING INHERITANCE
• Lets take a real life example to understand this: Lets assume
that Human is a class that has properties such as height,
weight, colour etc and functionality such as eating(),
sleeping(), dreaming(), working() etc.
• Now we want to create Male and Female class, these classes
are different but since both Male and Female are humans
they share some common properties and behaviours
(functionality) so they can inherit those properties and
functionality from Human class and rest can be written in
their class separately.
• This approach makes us write less code as both the classes
inherited several properties and functions from base class
thus we didn’t need to re-write them.
• Also, this makes it easier to read the code.
6.2 REAL LIFE EXAMPLE OF INHERITANCE
• Inheritance as the acquisition of a possession,
condition, or trait from past generations.
• In object oriented design, inheritance has a similar
(not exactly the same) connotation.
• Inheritance means
Organizing classes in a hierarchy
Higher hierarchy inherits properties from lower hierarchy
Clubbing similar things into the same class
Classes go from general to specific as you go higher in
hierarchy
6.2 REAL LIFE EXAMPLE OF INHERITANCE …
• This means that the most basic class, also known as the base class, will
be the most general one.
• It is also known as the parent class or the super-class.
• For example ‘electronics’ is the base class and its child class will be
‘mobile phones’ or ‘sound systems’.
6.2 REAL LIFE EXAMPLE OF INHERITANCE …
• This means that the most basic class, also known as the base class, will
be the most general one.
• It is also known as the parent class or the super-class.
• For example ‘electronics’ is the base class and its child class will be
‘mobile phones’ or ‘sound systems’.
• Using mathematical notations, the set of phones is a subset of the set of
electronics, but a superset of the set of landlines.
• The correspondence between levels is often referred to as an “is a”
relationship, i.e. a phone is an electronics item, and a landline is a
phone.
6.2 REAL LIFE EXAMPLE OF INHERITANCE …
• As we go higher in the hierarchy we become more and
more specific.
6.2 REAL LIFE EXAMPLE OF INHERITANCE …
• This hierarchical design is extremely useful
because it promotes the reuse of code.
• The common functionality can be grouped
together into the same class and differentiated
behaviours can form the specific cases or the
sub-classes.
• In technical terms, we say that the subclass
extends the superclass.
• When inheritance is used, the subclass
automatically inherits all methods from the
6.2 REAL LIFE EXAMPLE OF INHERITANCE …
• The subclass differentiates itself from its superclass by
the following 2 methods.
• It can augment the superclass by adding new fields and
new methods.
• It override existing behaviours by providing a new
implementation of an existing method.
Class — A group of similar objects
Fields — Properties of a class
Objects — Instances of a class
Methods — Actions that can be applied on objects
Constructor — Action that is used to create an object
7.0 BENEFITS OF OBJECT ORIENTED PROGRAMMING (OOP)
• Object-Oriented Programming is a
programming approach which familiars us with
the concepts of classes, objects, inheritance,
polymorphism, etc.
• OOP shows the relationship between the
objects, how they relate and how they
communicate with each other in order to
manipulate data.
• It is beneficial in many ways as well as it has
countless applications.
7.0 BENEFITS OF OBJECT ORIENTED PROGRAMMING (OOP) …
• Some of the benefits are :
OOP makes easier to design the software.
It enhances productivity.
It’s easy to test, debug, and maintain.
It gives the reusability.
OOP’s inheritance method helps to lessen the development
time
OOP coding is more accurate than procedural coding.
Hiding and abstraction make the data safe and secure, with less
data corruption.
• OOP is most demandable because of writing sizeable and
composite software.
7.0 BENEFITS OF OBJECT ORIENTED PROGRAMMING (OOP) …
• It is easy to model a real system as real objects are
represented by programming objects in OOP.
• The objects are processed by their member data and functions.
• It is easy to analyze the user requirements.
• With the help of inheritance, we can reuse the existing class
to derive a new class such that the redundant code is
eliminated and the use of existing class is extended.
• This saves time and cost of program.
• In OOP, data can be made private to a class such that only
member functions of the class can access the data.
• This principle of data hiding helps the programmer to build a secure
program that can not be invaded by code in other part of the
program.
7.0 BENEFITS OF OBJECT ORIENTED PROGRAMMING (OOP) …
• With the help of polymorphism, the same
function or same operator can be used for
different purposes.
• This helps to manage software complexity easily.
• Large problems can be reduced to smaller and
more manageable problems.
• It is easy to partition the work in a project based on
objects.
• It is possible to have multiple instances of an
object to co-exist without any interference
• i.e. each object has its own separate member
7.1 APPLICATIONS OF OBJECT ORIENTED PROGRAMMING (OOP)
User interface design such as windows,
menu.
Real Time Systems
Simulation and Modeling
Object oriented databases
AI and Expert System
Neural Networks and parallel
programming
Decision support and office automation
7.1 APPLICATIONS OF OBJECT ORIENTED PROGRAMMING (OOP)
…
1) Real-Time Systems Design
• A system is said to be Real-Time if it is required to complete its work and
delivers its services on time i.e. Flight Control System etc.
• Object-oriented techniques make it easier to control the complexities
related to real-time system design.
• These techniques give an integrated framework which involves the
schedulable analysis and developmental specifications.
• It has two main types
• Hard Real-Time System: Purely deterministic and 100% time
constraint system
• i.e. Satellite launching stations, Missile launching stations and Air
Bags Controls in cars etc.
• Soft Real-Time System: The meeting of the deadline is not compulsory
for every time or for every task but the process should be processed
and give the result
7.1 APPLICATIONS OF OBJECT ORIENTED PROGRAMMING (OOP)
…
2) Simulation and Modelling System
• The varying specification of variables makes it
difficult to build complex systems such as
ecology, zoology, and agronomic systems.
• Modeling and understanding interactions
explicitly are required for simulating complex
systems.
• Object-oriented Programming gives the
substitute approach for making these complex
modeling systems easier.
7.1 APPLICATIONS OF OBJECT ORIENTED PROGRAMMING (OOP)
…
3) Object-Oriented Database (ODBMS)
• The object-oriented database enables us to represent
data in the form of objects.
• It permits developers to model complex data easily and
captures the relationships in a natural way.
• It is also known as Object Database Management
Systems (ODBMS).
• To let the object maintain their identity and integrity,
these databases try to balance a relationship between the
real-world and database objects.
• Identities of objects are identified and operations are
then performed on these objects.
7.1 APPLICATIONS OF OBJECT ORIENTED PROGRAMMING (OOP)
…
4) Client-Server System
• A client-server is a software structural design model comprises of client
systems and server systems, both of which communicate over a
computer network or may communicate on the same computer.
• Because of object-oriented programming, Client-Server Systems offer
the IT infrastructure i.e. operating systems, networks, and hardware,
etc., creating object-oriented Client-Server Internet (OCSI) applications.
• These applications have three major technologies:
The Client Server
Object-Oriented Programming
The Internet
• These models have also structural functionality for email exchange and
Web/database access.
7.1 APPLICATIONS OF OBJECT ORIENTED PROGRAMMING (OOP)
…
5) Hypertext, Hypermedia
• Hypertext means text augmented with links.
• OOP also helps in laying out a framework for Hypertext which
is suitable for various media approaches.
• Hypertext is basically similar to that of regular text as it can be
stored, searched, and edited effortlessly.
• The main disparity is that hypertext is text with pointers to
other text as well.
• Hypermedia is an extension to hypertext that gives facilities like
handling sound and video.
• It’s a superset of hypertext.
• Documents having hypermedia, not only have links to other
pieces of text but also to various other forms of media, varies
7.1 APPLICATIONS OF OBJECT ORIENTED PROGRAMMING (OOP)
…
6) Neural Networking And Parallel Programming
• It is very useful in addresses the setback of
prediction and estimation of complex time-
varying systems.
• Firstly, the whole time-varying process is
divided into numerous time intervals.
• Then, neural networks are developed in a
specific time interval to scatter the load of
several networks.
• OOP simplifies the whole process by simplifying
the estimation and prediction capability of
7.1 APPLICATIONS OF OBJECT ORIENTED PROGRAMMING (OOP)
…
7) Office Automation Systems
• These involve formal and informal electronic
systems mainly concerned with information
sharing and communication to and from people
inside as well as external of the association
• i.e. email, Word processing, Web calendars,
Desktop publishing, etc.
7.1 APPLICATIONS OF OBJECT ORIENTED PROGRAMMING (OOP)
…
8) CIM (Computer Integrated Manufacturing) /
CAD (Computer Aided Design) /
CAM (Computer Aided Manufacturing) Systems
• OOP can also be used in developing and
designing the applications as it allows people to
trim down the effort involved.
• Such as, it is used in designing blueprints,
flowcharts, etc.
• OOP makes it easier for the designers and
engineers to produce these flowcharts and
7.1 APPLICATIONS OF OBJECT ORIENTED PROGRAMMING (OOP)
…
9) AI Expert Systems
• These are computer applications which use databases
of expert knowledge to make decisions in many areas
as medical diagnosis.
• Their advice and decisions are beyond the reach of a
human brain as they are reliable, highly responsive
and understandable.
• There are many more applications of object-oriented
programming OOP is widely used in developing and
designing applications such as office automation
systems etc.

Introduction to object oriented programming.pptx

  • 1.
  • 2.
    1.0 WHAT ISCOMPUTER PROGRAMMING? • Today, most people don't need to know how a computer works. • Most people can simply turn on a computer or a mobile phone and point at some little graphical object on the display, click a button or swipe a finger or two, and the computer does something. • An example would be to get weather information from the net and display it. • How to interact with a computer program is all the average person needs to know. • But, since you are going to learn how to write computer programs, you need to know a little bit about how a
  • 3.
    1.0 WHAT ISCOMPUTER PROGRAMMING? … • Now before we understand what programming is, you must know what is a computer. • A computer is a device that can accept human instruction, processes it and responds to it or a computer is a computational device which is used to process the data under the control of a computer program. • Program is a sequence of instruction along with data. • The basic components of a computer are: • Input unit • Central Processing Unit(CPU) • Output unit
  • 4.
    1.0 WHAT ISCOMPUTER PROGRAMMING? … • The CPU is further divided into three parts- • Memory unit • Control unit • Arithmetic Logic unit • Most of us have heard that CPU is called the brain of our computer because it accepts data, provides temporary memory space to it until it is stored(saved) on the hard disk, performs logical operations on it and hence processes(here also means converts) data into information. • We all know that a computer consists of hardware (H/W) and software (S/W). • Software (S/W) is a set of programs that performs multiple tasks together. • An operating system is also a software (system software) that
  • 5.
    1.1 INTRODUCTION TOCOMPUTER PROGRAMMING? • A program is a set of instructions given to a computer to perform a specific operation. • or computer is a computational device which is used to process the data under the control of a computer program. • While executing the program, raw data is processed into a desired output format. • These computer programs are written in a programming language which are high level languages. • High level languages are nearly human languages which are more complex than the computer understandable language which are called machine (m/c) language, or low level.
  • 6.
    1.1 INTRODUCTION TOCOMPUTER PROGRAMMING? … • So after knowing the basics, we are ready to create a very simple and basic program. • Like we have different languages to communicate with each other, likewise, we have different languages like C, C++, C#, Java, python, etc. to communicate with the computers. • The computer only understands binary language (the language of 0’s and 1’s) also called machine- understandable language or low-level language but the programs we are going to write are in a high-level language which is almost similar to
  • 7.
    1.1 INTRODUCTION TOCOMPUTER PROGRAMMING? … • Before getting into computer programming, let us first understand computer programs and what they do. • A computer program is a sequence of instructions written using a Computer Programming Language to perform a specified task by the computer. • The two important terms that we have used in the above definition are − • Sequence of instructions
  • 8.
    1.1 INTRODUCTION TOCOMPUTER PROGRAMMING? … • To understand these terms, consider a situation when someone asks you about how to go to a nearby HOTEL. • What exactly do you do to tell him the way to go to HOTEL? • You will use Human Language to tell the way to go to HOTEL, something as follows − First go straight, after half kilometer, take left from the red light and then drive around one kilometer and you will find HOTEL at the right.
  • 9.
    1.1 INTRODUCTION TOCOMPUTER PROGRAMMING? … • Here, you have used English Language to give several steps to be taken to reach HOTEL. • If they are followed in the following sequence, then you will reach HOTEL − STEP 1: Go straight STEP 2: Drive half kilometer STEP 3: Take left STEP 4: Drive around one kilometer STEP 5: Search for HOTEL at your right side
  • 10.
    1.1 INTRODUCTION TOCOMPUTER PROGRAMMING? … • Now, try to map the situation with a computer program. The above sequence of instructions is actually a Human Program written in English Language, which instructs on how to reach HOTEL from a given starting point. This same sequence could have been given in Spanish, Hindi, Arabic, or any other human language, provided the person seeking direction knows any of these languages.
  • 11.
    1.1 INTRODUCTION TOCOMPUTER PROGRAMMING? … • Now, let's go back and try to understand a computer program, which is a sequence of instructions written in a Computer Language to perform a specified task by the computer. • Following is a simple program written in Python programming Language − • The above computer program instructs the computer to print "Hello, World!" on the computer screen.  A computer program is also called a computer software, which can range from two lines to millions of lines of instructions.  Computer program instructions are also called program source code and computer programming is also called program coding.  A computer without a computer program is just a dump box; it is programs that make computers active. print "Hello, World!"
  • 12.
    1.1 INTRODUCTION TOCOMPUTER PROGRAMMING? … • As we have developed so many languages to communicate among ourselves, computer scientists have developed several computer- programming languages to provide instructions to the computer (i.e., to write computer programs).
  • 13.
    1.1 INTRODUCTION TOCOMPUTER PROGRAMMING? … • The piece of code given below performs a basic task of printing “Hello, World!” on the console screen. • We must know that keyboard, scanner, mouse, microphone, etc. are various examples of input devices and monitor(console screen), printer, speaker, etc. are the examples of output devices. main() { clrscr(); printf(“Hello, World!"); getch(); }
  • 14.
    1.1 INTRODUCTION TOCOMPUTER PROGRAMMING? … • At this stage, you might not be able to understand in- depth how this code prints something on the screen. • The main() is a standard function that you will always include in any program that you are going to create from now onwards. • Note that the execution of the program starts from the main() function. • The clrscr() function is used to see only the current output on the screen while the printf () function helps us to print the desired output on the screen. • Also, getch() is a function that accepts any character input from the keyboard. • In simple words, we need to press any key to
  • 15.
    1.1 INTRODUCTION TOCOMPUTER PROGRAMMING? … • Between high-level language and machine language there are assembly language also called symbolic machine code. • Assembly language are particularly computer architecture specific. • Utility program (Assembler) is used to convert assembly code into executable machine code. • High Level Programming Language are portable but require Interpretation or compiling to convert it into a machine language which is
  • 16.
    1.1 INTRODUCTION TOCOMPUTER PROGRAMMING? … • If you understood what a computer program is, then we will say: the act of writing computer programs is called computer programming. • As we mentioned earlier, there are hundreds of programming languages, which can be used to write computer programs and following are a few of them − • Java • C • C++ • Python • PHP • Perl • Ruby
  • 17.
    1.2 USES OFCOMPUTER PROGRAMS • Today computer programs are being used in almost every field, household, agriculture, medical, entertainment, defense, communication, etc. • Listed below are a few applications of computer programs − MS Word, MS Excel, Adobe Photoshop, Internet Explorer, Chrome, etc., are examples of computer programs. Computer programs are being used to develop graphics and special effects in movie making. Computer programs are being used to perform Ultrasounds, X-Rays, and other medical examinations. Computer programs are being used in our mobile phones
  • 18.
    1.4 COMPUTER PROGRAMMER •Someone who can write computer programs or in other words, someone who can do computer programming is called a Computer Programmer. • Based on computer programming language expertise, we can name a computer programmers as follows − C Programmer C++ Programmer Java Programmer Python Programmer PHP Programmer Perl Programmer Ruby Programmer
  • 19.
    1.5 ALGORITHM • Fromprogramming point of view, an algorithm is a step-by-step procedure to resolve any problem. • An algorithm is an effective method expressed as a finite set of well-defined instructions. • Thus, a computer programmer lists down all the steps required to resolve a problem before writing the actual code.
  • 20.
    1.5 ALGORITHM … •Following is a simple example of an algorithm to find out the largest number from a given list of numbers − • The above algorithm has been written in a crude way to help beginners understand the concept. • You will come across more standardized ways of writing computer algorithms as you move on to advanced levels of 1. Get a list of numbers L1, L2, L3....LN 2. Assume L1 is the largest, Largest = L1 3. Take next number Li from the list and do the following 4. If Largest is less than Li 5. Largest = Li 6. If Li is last number from the list then 7. Print value stored in Largest and come out 8. Else repeat same process starting from step 3
  • 21.
    1.6 HIERARCHY OFCOMPUTER LANGUAGE
  • 22.
    1.6 HIERARCHY OFCOMPUTER LANGUAGE … • There have been many programming language some of them are listed below: C Python C++ C# R Ruby COBOL ADA Java Fortran BASIC Altair BASIC True BASIC Visual BASIC GW BASIC QBASIC PureBASIC PASCAL Turbo Pascal GO ALGOL LISP SCALA Swift Rust Prolog Reia Racket Scheme Shimula Perl PHP Java Script CoffeeScript VisualFoxPro Babel Logo Lua Smalltalk Matlab F F# Dart Datalog dbase Haskell dylan Julia ksh metro Mumps Nim OCaml pick TCL D CPL Curry ActionScript Erlang Clojure DarkBASCIC Assembly
  • 23.
    1.6 HIERARCHY OFCOMPUTER LANGUAGE … • Most Popular Programming Languages – C Python C++ Java SCALA C# R Ruby Go Swift JavaScript
  • 24.
    1.7 CHARACTERISTICS OFCOMPUTER LANGUAGE … A programming language must be simple, easy to learn and use, have good readability and human recognizable. Abstraction is a must-have Characteristics for a programming language in which ability to define the complex structure and then its degree of usability comes. A portable programming language is always preferred. Programming language’s efficiency must be high so that it can be easily converted into a machine code and executed consumes little space in memory. A programming language should be well structured and documented so that it is suitable for application development. Necessary tools for development, debugging, testing, maintenance of a program must be provided by a programming language. A programming language should provide single environment known as Integrated Development Environment(IDE). 
  • 25.
    2.0 WHAT ISOBJECT ORIENTED PROGRAMMING (OOP) ? • Object Oriented programming (OOP) is a programming paradigm that includes or relies on the concept of classes and objects. • It is used to structure a software program into simple, reusable pieces of code blueprints (usually called classes) which are used to create individual instances of objects. • Because OOP is a programming paradigm, there are many object-oriented programming languages including: C++, Java, and Python.
  • 26.
    • A programmerdesigns a software program by organizing related pieces of information and behaviors together into a template called a class. • Then individual objects are instantiated or created from the class template; these objects usually represent a real world thing. • The entire software program runs by having multiple objects interact with 2.0 WHAT IS OBJECT ORIENTED PROGRAMMING (OOP) ? …
  • 27.
    2.1 WHY OOP? •OOP makes code organized, reusable, and easy to maintain; It follows the DRY method (Don’t Repeat Yourself). • Benefits of OOP include security; OOP prevents unwanted access to data, or exposing proprietary code through encapsulation and abstraction - both are discussed further in the Principles of OOP section. • So how do programmers create Object Oriented programs? Well the short answer is by making classes, and creating objects from the classes.
  • 28.
    2.1 WHY OOP?… • In OOP everything is an object. • Classes form the blueprint for how data & behaviors are structured. • Objects are created for specific instances of a class. • As a programmer, you might create a dog class (blueprint) as a standard way to organize all the important information about dogs, and then instantiate an individual dog as an object created from the dog class - like your dog Fluffy.
  • 29.
    2.2 BUILDING BLOCKSOF OOP • The code building blocks to build an OOP program we’ll discuss are: classes objects methods attributes
  • 30.
    2.3 EXAMPLE OOPSTRUCTURE • Let’s take a real world problem, and conceptually design an OOP software program. • Imagine running a pet sitting camp, with hundreds of pets, and you have to keep track of the names, ages, and days attended for each pet. • How would you design simple, reusable software to model the pets?
  • 31.
    2.3 EXAMPLE OOPSTRUCTURE • In the pet sitting camp example, here’s how a programmer could think about organizing an OOP: 1) Group pets into categories Like Dog, Cat • Determine the information the software should model for each pet category 2) Create classes • Classes a blueprint of information for each pet 3) Add Attributes to classes • Data fields to store for each pet, like name 4) Add Behaviors to classes • Functionality that each pet needs to do, like bark 5) Create objects from the class • Objects are individual instances of the class template • In our case dogs like Rufus & Fluffy
  • 32.
    2.4 AN OBJECT-ORIENTEDCLASS • If we think of a real-world object, such as a television it will have several features and properties: We do not have to open the case to use it. We have some controls to use it (buttons on the box, or a remote control). We can still understand the concept of a television, even if it is connected to a DVD player. It is complete when we purchase it, with any external requirements well documented. The TV will not crash! • In many ways this compares very well to the notion of a class
  • 33.
    2.4.1 THE CONCEPTOF A CLASS- TELEVISION EXAMPLE
  • 34.
    2.4.1 THE CONCEPTOF A CLASS- TELEVISION EXAMPLE … • A class should: Provide a well-defined interface - such as the remote control of the television. Represent a clear concept - such as the concept of a television. Be complete and well-documented - the television should have a plug and should have a manual that documents all features. The code should be robust - it should not crash, like the television.
  • 35.
    2.4.2 A CLASS •With a functional programming language (like C) we would have the component parts of the television scattered everywhere and we would be responsible for making them work correctly - there would be no case surrounding the electronic components. • Humans use class based descriptions all the time - what is a duck? • Classes allow us a way to represent complex structures within a programming language. • They have two components: States - (or data) are the values that the object has. Methods - (or behaviour) are the ways in which the object can interact with its data, the actions.
  • 36.
    2.4.3 THE TELEVISIONCLASS EXAMPLE • An instance of a class is called an object.
  • 37.
    2.5 AN OBJECT •An object is an instance of a class. • You could think of a class as the description of a concept, and an object as the realization of this description to create an independent distinguishable entity. • For example, in the case of the Television, the class is the set of plans (or blueprints) for a generic television, whereas a television object is the realization of these plans into a real-world physical television. • So there would be one set of plans (the class), but there could be thousands of real-world
  • 38.
    2.5 AN OBJECT… • Objects can be concrete (a real-world object, a file on a computer) or could be conceptual (such as a database structure) each with its own individual identity. • Figure shows an example where the Television class description is realized into several television objects. • These objects should have their own identity and are independent from each other. • For example, if the channel is changed on one television it will not change on the other
  • 39.
    2.5.1 THE TELEVISIONOBJECTS EXAMPLE
  • 40.
    2.5.2 THE HOUSEOBJECTS EXAMPLE • A class is a blueprint for creating an object. • It is similar to the blue print of a house.
  • 41.
    2.5.3 THE PARROTOBJECTS EXAMPLE • One of the popular approaches to solve a programming problem is by creating objects. • This is known as Object-Oriented Programming (OOP). • An object has two characteristics: attributes behavior • Let's take an example: • A parrot is can be an object, as it has the following properties: name, age, color as attributes singing, dancing as behavior • The concept of OOP in programming focuses on creating reusable code.
  • 42.
    2.5.3 THE PARROTOBJECTS EXAMPLE : CLASS • A class is a blueprint for the object. • We can think of class as a sketch of a parrot with labels. • It contains all the details about the name, colors, size etc. • Based on these descriptions, we can study about the parrot. • Here, a parrot is an object. • The example for class of parrot can be : • Here, we use the class keyword to define an empty class Parrot. • From class, we construct instances. class Parrot: pass
  • 43.
    2.5.3 THE PARROTOBJECTS EXAMPLE : OBJECT • An object (instance) is an instantiation of a class. • When class is defined, only the description for the object is defined. • Therefore, no memory or storage is allocated. • The example for object of parrot class can be: • Here, obj is an object of class Parrot. obj = Parrot()
  • 44.
    2.5.4 THE FRUITOBJECTS EXAMPLE
  • 45.
    2.5.5 THE CAROBJECTS EXAMPLE • So, a class is a template for objects, and an object is an instance of a class. • When the individual objects are created, they inherit all the variables and functions from the class.
  • 46.
    3.0 OBJECT ORIENTEDPROGRAMMING (OOPS) CONCEPT • As the name suggests, Object-Oriented Programming or OOPs refers to languages that uses objects in programming. • Object-oriented programming aims to implement real-world entities like inheritance, hiding, polymorphism etc. in programming. • The main aim of OOP is to bind together the data and the functions that operate on them so that no other part of the code can access this data except that function.
  • 47.
    3.0 OBJECT ORIENTEDPROGRAMMING (OOPS) CONCEPT …
  • 48.
    3.0 OBJECT ORIENTEDPROGRAMMING (OOPS) CONCEPT … • OOPs Concepts: Class Object Polymorphism Inheritance Encapsulation Abstraction Method Message Passing
  • 49.
    3.1 OBJECT ORIENTEDPROGRAMMING (OOPS) CONCEPT : ENCAPSULATION • Say we have a program. • It has a few logically different objects which communicate with each other — according to the rules defined in the program. • Encapsulation is achieved when each object keeps its state private, inside a class. • Other objects don’t have direct access to this state. • Instead, they can only call a list of public functions — called methods.
  • 50.
    3.1 OBJECT ORIENTEDPROGRAMMING (OOPS) CONCEPT : ENCAPSULATION … • So, the object manages its own state via methods — and no other class can touch it unless explicitly allowed. • If you want to communicate with the object, you should use the methods provided. • But (by default), you can’t change the state.
  • 51.
    3.1 OBJECT ORIENTEDPROGRAMMING (OOPS) CONCEPT : ENCAPSULATION … • Let’s say we’re building a tiny Sims game. • There are people and there is a cat. • They communicate with each other. • We want to apply encapsulation, so we encapsulate all “cat” logic into a Cat class. • It may look like this:
  • 52.
    3.1 OBJECT ORIENTEDPROGRAMMING (OOPS) CONCEPT : ENCAPSULATION … • You can feed the cat. • But you can’t directly change how hungry the cat is.
  • 53.
    3.1 OBJECT ORIENTEDPROGRAMMING (OOPS) CONCEPT : ENCAPSULATION … • Here the “state” of the cat is the private variables mood, hungry and energy. • It also has a private method meow(). • It can call it whenever it wants, the other classes can’t tell the cat when to meow. • What they can do is defined in the public methods sleep(), play() and feed(). • Each of them modifies the internal state somehow and may invoke meow(). • Thus, the binding between the private state and public methods is made. • This is encapsulation.
  • 54.
    3.1 WHAT ISENCAPSULATION? (DEFINITION 1) • In object-oriented computer programming languages, the notion of encapsulation refers to the bundling of data, along with the methods that operate on that data, into a single unit. • Many programming languages use encapsulation frequently in the form of classes. • A class is a program-code-template that allows developers to create an object that has both variables (data) and behaviors (functions or methods). • A class is an example of encapsulation in that it consists of data and methods that have been
  • 55.
    3.1 WHAT ISENCAPSULATION? (DEFINITION 1)… • Encapsulation may also refer to a mechanism of restricting the direct access to some components of an object, such that users cannot access state values for all of the variables of a particular object. • Encapsulation can be used to hide both data members and data functions or methods associated with an instantiated class or object.
  • 56.
    3.1 WHAT ISENCAPSULATION? (DEFINITION 2) • Encapsulation is one of the fundamental concepts in object- oriented programming (OOP). • It describes the idea of bundling data and methods that work on that data within one unit, e.g., a class in Java. • This concept is also often used to hide the internal representation, or state, of an object from the outside. • This is called information hiding. • The general idea of this mechanism is simple. • If you have an attribute that is not visible from the outside of an object, and bundle it with methods that provide read or write access to it, then you can hide specific information and control access to the internal state of the object.
  • 57.
    3.1 WHAT ISENCAPSULATION? (DEFINITION 2) … • If you’re familiar with any object-oriented programming language, you probably know that these methods as getter and setter methods. • As the names indicate, a getter method retrieves an attribute, and a setter method changes it. • Depending on the methods that you implement, you can decide if an attribute can be read and changed, or if it’s read-
  • 58.
    3.1 WHAT ISENCAPSULATION? (DEFINITION 3) • In normal terms Encapsulation is defined as wrapping up of data and information under a single unit. • In Object Oriented Programming, Encapsulation is defined as binding together the data and the functions that manipulates them. • Consider a real life example of encapsulation, in a company there are different sections like the accounts section, finance section, sales section etc. • The finance section handles all the financial transactions and keep records of all the data related to finance. • Similarly the sales section handles all the sales related activities and keep records of all the sales. • Now there may arise a situation when for some reason an official from finance section needs all the data about sales in a
  • 59.
    3.1 WHAT ISENCAPSULATION? (DEFINITION 3) … • In this case, he is not allowed to directly access the data of sales section. • He will first have to contact some other officer in the sales section and then request him to give the particular data. • This is what encapsulation is. • Here the data of sales section and the employees that can manipulate them are wrapped under a single name “sales section”. • Encapsulation also lead to data abstraction or hiding. • As using encapsulation also hides the data. • In the above example the data of any of the section like sales, finance or accounts is hidden from any other section.
  • 60.
    3.1 WHAT ISENCAPSULATION? (DEFINITION 4) • Encapsulation is: Binding the data with the code that manipulates it. It keeps the data and the code safe from external interference • Looking at the example of a power steering mechanism of a car. • Power steering of a car is a complex system, which internally have lots of components tightly coupled together, they work synchronously to turn the car in the desired direction. • It even controls the power delivered by the engine to the steering wheel. • But to the external world there is only one interface is available and rest of the complexity is hidden. • Moreover, the steering unit in itself is complete and independent.
  • 61.
    3.1 WHAT ISENCAPSULATION? (DEFINITION 4) … • Similarly, same concept of encapsulation can be applied to code. • Encapsulated code should have following characteristics: Everyone knows how to access it. Can be easily used regardless of implementation details. There shouldn’t any side effects of the code, to the rest of the application. • The idea of encapsulation is to keep classes separated and prevent them from having tightly
  • 62.
    3.2 REAL-TIME EXAMPLEOF ENCAPSULATION Real-time Example 1: • School bag is one of the most real examples of Encapsulation. • School bag can keep our books, pens, etc. Real-time Example 2: • When you log into your email accounts such as Gmail, Yahoo Mail, or Rediff mail, there is a lot of internal processes taking place in the backend and you have no control over it. • When you enter the password for logging, they are retrieved in an encrypted form and verified, and then you are given access to your account. • You do not have control over it that how the password has been verified.
  • 63.
    3.2 REAL-TIME EXAMPLEOF ENCAPSULATION … Real-time Example 3: • Suppose you have an account in the bank. • If your balance variable is declared as a public variable in the bank software, your account balance will be known as public, In this case, anyone can know your account balance. • So, would you like it? Obviously No. • So, they declare balance variable as private for making your account safe, so that anyone cannot see your account balance. • The person who has to see his account balance, will have to access only private members through methods defined inside that class and this method will ask your account holder name or user Id, and password for authentication. • Thus, we can achieve security by utilizing the concept of data hiding. This is called Encapsulation.
  • 64.
    3.2 REAL-TIME EXAMPLEOF ENCAPSULATION Real-time Example 4: • The interaction between a user and a mobile phone. • The user does not need to know the internal working of the mobile phone to operate, so this is called abstraction. • Encapsulation is a way to achieve "information hiding" so, following your example, you don't "need to know the internal working of the mobile phone to operate" with it. • You have an interface to use the device behaviour without knowing implementation
  • 65.
    4.0 WHAT ISABSTRACTION? • Abstraction is the process of hiding the internal details of an application from the outer world. • Abstraction is used to describe things in simple terms. • It’s used to create a boundary between the application and the client programs.
  • 66.
    4.1 ABSTRACTION INREAL LIFE • Abstraction is present in almost all the real life machines. Your car is a great example of abstraction. • You can start a car by turning the key or pressing the start button. • You don’t need to know how the engine is getting started, what all components your car has. • The car internal implementation and complex logic is completely hidden from the user. We can heat our food in Microwave. • We press some buttons to set the timer and type of food. • Finally, we get a hot and delicious meal. • The microwave internal details are hidden from us. • We have been given access to the functionality in a very simple
  • 67.
    4.1 ABSTRACTION INREAL LIFE … • Data abstraction refers to providing only essential information to the outside world and hiding their background details, i.e., to represent the needed information in program without presenting the details. • Data abstraction is a programming (and design) technique that relies on the separation of interface and implementation. • Let's take one real life example of a TV, which you can turn on and off, change the channel, adjust the volume, and add external components such as speakers, VCRs, and DVD players, BUT you do not know its internal details, that is, you do not know how it receives signals over the air or through a cable, how it translates them,
  • 68.
    4.1 ABSTRACTION INREAL LIFE … • Thus, we can say a television clearly separates its internal implementation from its external interface and you can play with its interfaces like the power button, channel changer, and volume control without having any knowledge of its internals. • Abstraction is a programming methodology in which details of the programming codes are hidden away from the user, and only the essential things are displayed to the user. • Abstraction is concerned with ideas rather than events. • It’s like a user running a program (Web Browser)
  • 69.
    4.1 ABSTRACTION INREAL LIFE … • I’m a coffee addict. • So, when I wake up in the morning, I go into my kitchen, switch on the coffee machine and make coffee. • Sounds familiar? • Making coffee with a coffee machine is a good example of abstraction. • You need to know how to use your coffee machine to make coffee. • You need to provide water and coffee beans, switch it on and select the kind of coffee you want to get. • The thing you don’t need to know is how the coffee machine is working internally to brew a fresh cup of delicious coffee. • You don’t need to know the ideal temperature of the water or the amount of ground coffee you need to use. • Someone else worried about that and created a coffee machine that now acts as an abstraction and hides all these details. • You just interact with a simple interface that doesn’t require any knowledge about the internal implementation.
  • 70.
    4.2 ABSTRACTION INOOPS • ABSTRACTION is the concept of object-oriented programming that "shows" only essential attributes and "hides" unnecessary information. • The main purpose of abstraction is hiding the unnecessary details from the users. • Abstraction is selecting data from a larger pool to show only relevant details of the object to the user. • It helps in reducing programming complexity and efforts. • It is one of the most important concepts of
  • 71.
    4.3 LET'S STUDYABSTRACTION CONCEPT WITH AN EXAMPLE • Suppose you want to create a banking application and you are asked to collect all the information about your customer. • There are chances that you will come up with following information about the customer.
  • 72.
    4.3 LET'S STUDYABSTRACTION CONCEPT WITH AN EXAMPLE … • But, not all of the above information is required to create a banking application. • So, you need to select only the useful information for your banking application from that pool. • Data like name, address, tax information, etc. make sense for a banking application.
  • 73.
    4.3 LET'S STUDYABSTRACTION CONCEPT WITH AN EXAMPLE … • Since we have fetched/removed/selected the customer information from a larger pool, the process is referred as Abstraction. • However, the same information once extracted can be used for a wide range of applications. • For instance, you can use the same data for hospital application, job portal application, a Government database, etc. with little or no modification. • Hence, it becomes your Master Data. • This is an advantage of Abstraction.
  • 74.
    4.4 WHAT ARETHE DIFFERENT TYPES OF ABSTRACTION There are two types of abstraction. 1) Data Abstraction 2) Process Abstraction
  • 75.
    4.4 WHAT ARETHE DIFFERENT TYPES OF ABSTRACTION : 1) DATA ABSTRACTION o When the object data is not visible to the outer world, it creates data abstraction. o If needed, access to the Objects’ data is provided through some methods.
  • 76.
    4.4 WHAT ARETHE DIFFERENT TYPES OF ABSTRACTION : 2) PROCESS ABSTRACTION  We don’t need to provide details about all the functions of an object.  When we hide the internal implementation of the different functions involved in a user operation, it creates process abstraction.
  • 77.
    4.5 ADVANTAGES OFABSTRACTION The main benefit of using an abstract class is that it allows you to group several related classes as siblings. Abstraction helps to reduce the complexity of the design and implementation process of software. Another advantage of using this feature is that when the code evolves and you need to make some adjustments in the code then you only need to modify the high level class where you have declared the members as private. Since none class is accessing these data members directly, you do not need to change the low level(user
  • 78.
    4.5 ADVANTAGES OFABSTRACTION … Imagine if you had made these data members public, if at some point you want to change the code, you would have to make the necessary adjustments to all the classes that are accessing the members directly. Makes the application secure by making data private and avoiding the user level error that may corrupt the data. This avoids code duplication and increases the
  • 79.
    4.6 DIFFERENCE B/WABSTRACTION AND ENCAPSULATION Abstraction Encapsulation  Abstraction solves the issues at the design level.  Encapsulation solves it implementation level.  Abstraction is about hiding unwanted details while showing most essential information.  Encapsulation means binding the code and data into a single unit.  Abstraction allows focussing on what the information object must contain  Encapsulation means hiding the internal details or mechanics of how an object does something for security reasons.
  • 80.
    5.0 WHAT ISPOLYMORPHISM ? • The word polymorphism means having many forms. • In simple words, we can define polymorphism as the ability of a message to be displayed in more than one form.
  • 81.
    5.0 WHAT ISPOLYMORPHISM ? … • The word polymorphism is used in various contexts and describes situations in which something occurs in several different forms. • In computer science, it describes the concept that objects of different types can be accessed through the same interface. • Each type can provide its own, independent implementation of this interface. • It is one of the core concepts of object-oriented programming (OOP).
  • 82.
    5.0 WHAT ISPOLYMORPHISM ? … • If you’re wondering if an object is polymorphic, you can perform a simple test. • If the object successfully passes multiple is-a or instanceof tests, it’s polymorphic. • As I’ve described in my post about inheritance, all Java classes extend the class Object. • Due to this, all objects in Java are polymorphic because they pass at least two instanceof checks.
  • 83.
    5.1 REAL LIFEEXAMPLE OF POLYMORPHISM: • A person at the same time can have different characteristic. • Like a man at the same time is a father, a husband, an employee. • So the same person posses different behaviour in different situations. This is called polymorphism. • Polymorphism is considered as one of the important features of Object Oriented Programming. • Polymorphism allows us to perform a single action in different ways. • In other words, polymorphism allows you to define one interface and have multiple implementations. • The word “poly” means many and “morphs” means forms,
  • 84.
    5.1 REAL LIFEEXAMPLE OF POLYMORPHISM … • Polymorphism is one of the OOPs feature that allows us to perform a single action in different ways. • For example, lets say we have a class Animal that has a method sound(). • Since this is a generic class so we can’t give it a implementation like: the lions roars, the pig oinks, and the cat meows, etc.
  • 85.
    5.1 REAL LIFEEXAMPLE OF POLYMORPHISM … • Suppose if you are in class room that time you behave like a student, when you are in market at that time you behave like a customer, when you at your home at that time you behave like a son or daughter, Here one person present in different-different behaviors.
  • 86.
    5.1 REAL LIFEEXAMPLE OF POLYMORPHISM … • You can see in the below Images, you can see, Man is only one, but he takes multiple roles like - he is a dad to his child, he is an employee, a salesperson and many more. • This is known as Polymorphism.
  • 87.
    5.1 REAL LIFEEXAMPLE OF POLYMORPHISM … • In today’s world, everything that we imagined in the past is becoming a reality. • Be it from the Sci-fi movies or our imagination and ideas, we have worked towards turning them into reality. • Similarly, programs (computer and programming languages) were designed to solve problems faster and with accuracy. • So, it is very crucial to understand programming concepts with real-life examples and context.
  • 88.
    5.1 REAL LIFEEXAMPLE OF POLYMORPHISM … • Today, we will learn How Polymorphism is connected to the real world? • Below we have a conversation between the Real World and Polymorphism. • Let’s have a look at the conversation. • Real World: Hye Poly! why you look so sad? • Polymorphism: Nothing dude, I am missing you a lot. • Real World: Thank you, buddy. • Even I miss you a lot. But don’t you think we are always
  • 89.
    5.2 POLYMORPHISM INOOPS • The word polymorphism is used in various contexts and describes situations in which something occurs in several different forms. • In computer science, it describes the concept that objects of different types can be accessed through the same interface. • Each type can provide its own, independent implementation of this interface. • It is one of the core concepts of object-oriented programming (OOP). • If you’re wondering if an object is polymorphic, you can perform a simple test. • If the object successfully passes multiple is-a or
  • 90.
    5.2 POLYMORPHISM INOOPS … • Polymorphism in programming languages occurs when there are one or more classes or objects related to each other by inheritance. • In other words, it is the ability of an object to take many forms. • Inheritance lets users inherit attributes and methods, and polymorphism uses these methods for performing different tasks. • So, the goal is communication but the approach is different. • For example, you have a smartphone for communication. • The communication mode you choose could be anything. • It can be a call, a text message, a picture message, mail, etc. • So, the goal is common that is communication, but their approach is different.
  • 91.
    5.3 POLYMORPHISM INOOP’S WITH EXAMPLE • We have one parent class, ‘Account’ with function of deposit and withdraw. • Account has 2 child classes. • The operation of deposit and withdraw is same for Saving and Checking accounts. • So the inherited methods from Account class will work.
  • 92.
    5.3 POLYMORPHISM INOOP’S WITH EXAMPLE… • Change in Software Requirement • There is a change in the requirement specification, something that is so common in the software industry. • You are supposed to add functionality privileged Banking Account with Overdraft Facility. • For a background, overdraft is a facility where you can withdraw an amount more than available the balance in your account. • So, withdraw method for privileged needs to implemented afresh. • But you do not change the tested piece of code in Savings and Checking account.
  • 93.
    5.3 POLYMORPHISM INOOP’S WITH EXAMPLE… 93
  • 94.
    5.3 POLYMORPHISM INOOP’S WITH EXAMPLE… Step 1 : • Such that when the "withdrawn" method for saving account is called a method from parent account class is executed.
  • 95.
    5.3 POLYMORPHISM INOOP’S WITH EXAMPLE… Step 2 : • But when the "Withdraw" method for the privileged account (overdraft facility) is called withdraw method defined in the privileged class is executed. • This is Polymorphism.
  • 96.
    5.3 POLYMORPHISM INOOP’S WITH EXAMPLE… • Polymorphism has been derived from a biological term that means ability of an organism to adopt multiple forms. • In OOPs, polymorphism refers to the ability of referring and processing multiple objects and classes through a unified interface. • Any object that satisfies multiple IS-A relationships is a candidate of being implemented as a polymorphic object.
  • 97.
    5.3 POLYMORPHISM INOOP’S WITH EXAMPLE… • For instance, the object of class Square IS-A Square; It IS-A Shape as well and It IS-An object as well. • It means that Object and Shape can be declared parent classes of child Square classes. • Therefore, a common interface Object can be used to refer to all objects of Square class. • Also, Shape interface can also be used to refer to all objects of Square class and so on. • This is due to the IS-A relationship of Square with Object and Shape classes.
  • 98.
    6.0 WHAT ISINHERITANCE IN OOPS? • Inheritance is one of the core concepts of object-oriented programming (OOP) languages. • It is a mechanism where you can to derive a class from another class for a hierarchy of classes that share a set of attributes and methods. • Inheritance is a mechanism in which one class acquires the property of another class. • For example, a child inherits the traits of his/her parents. • With inheritance, we can reuse the fields and methods of the existing class. • Hence, inheritance facilitates Reusability and is an important concept of OOPs.
  • 99.
    6.0 WHAT ISINHERITANCE IN OOPS? … • One of the most important concepts in object-oriented programming is that of inheritance. • Inheritance allows us to define a class in terms of another class, which makes it easier to create and maintain an application. • This also provides an opportunity to reuse the code functionality and fast implementation time. • When creating a class, instead of writing completely new data members and member functions, the programmer can designate that the new class should inherit the members of an existing class. • This existing class is called the base class, and the new
  • 100.
    6.0 WHAT ISINHERITANCE IN OOPS? … • One of the most important concepts in object-oriented programming is that of inheritance. • Inheritance allows us to define a class in terms of another class, which makes it easier to create and maintain an application. • This also provides an opportunity to reuse the code functionality and fast implementation time. • When creating a class, instead of writing completely new data members and member functions, the programmer can designate that the new class should inherit the members of an existing class. • This existing class is called the base class, and the new class is referred to as the derived class. • The idea of inheritance implements the is a relationship. • For example, mammal IS-A animal, dog IS-A mammal hence dog IS-A
  • 101.
    6.0 WHAT ISINHERITANCE IN OOPS? … • Inheritance is one of the feature of Object Oriented Programming System(OOPs), it allows the child class to acquire the properties (the data members) and functionality (the member functions) of parent class. What is child class? • A class that inherits another class is known as child class, it is also known as derived class or subclass. What is parent class? • The class that is being inherited by other class is known as parent class, super class or base class.
  • 102.
    6.1 WHAT ARETHE ADVANTAGES OF USING INHERITANCE • The main advantages of inheritance are code reusability and readability. • When child class inherits the properties and functionality of parent class, we need not to write the same code again in child class. • This makes it easier to reuse the code, makes us write the less code and the code becomes much more readable.
  • 103.
    6.1 WHAT ARETHE ADVANTAGES OF USING INHERITANCE • Lets take a real life example to understand this: Lets assume that Human is a class that has properties such as height, weight, colour etc and functionality such as eating(), sleeping(), dreaming(), working() etc. • Now we want to create Male and Female class, these classes are different but since both Male and Female are humans they share some common properties and behaviours (functionality) so they can inherit those properties and functionality from Human class and rest can be written in their class separately. • This approach makes us write less code as both the classes inherited several properties and functions from base class thus we didn’t need to re-write them. • Also, this makes it easier to read the code.
  • 104.
    6.2 REAL LIFEEXAMPLE OF INHERITANCE • Inheritance as the acquisition of a possession, condition, or trait from past generations. • In object oriented design, inheritance has a similar (not exactly the same) connotation. • Inheritance means Organizing classes in a hierarchy Higher hierarchy inherits properties from lower hierarchy Clubbing similar things into the same class Classes go from general to specific as you go higher in hierarchy
  • 105.
    6.2 REAL LIFEEXAMPLE OF INHERITANCE … • This means that the most basic class, also known as the base class, will be the most general one. • It is also known as the parent class or the super-class. • For example ‘electronics’ is the base class and its child class will be ‘mobile phones’ or ‘sound systems’.
  • 106.
    6.2 REAL LIFEEXAMPLE OF INHERITANCE … • This means that the most basic class, also known as the base class, will be the most general one. • It is also known as the parent class or the super-class. • For example ‘electronics’ is the base class and its child class will be ‘mobile phones’ or ‘sound systems’. • Using mathematical notations, the set of phones is a subset of the set of electronics, but a superset of the set of landlines. • The correspondence between levels is often referred to as an “is a” relationship, i.e. a phone is an electronics item, and a landline is a phone.
  • 107.
    6.2 REAL LIFEEXAMPLE OF INHERITANCE … • As we go higher in the hierarchy we become more and more specific.
  • 108.
    6.2 REAL LIFEEXAMPLE OF INHERITANCE … • This hierarchical design is extremely useful because it promotes the reuse of code. • The common functionality can be grouped together into the same class and differentiated behaviours can form the specific cases or the sub-classes. • In technical terms, we say that the subclass extends the superclass. • When inheritance is used, the subclass automatically inherits all methods from the
  • 109.
    6.2 REAL LIFEEXAMPLE OF INHERITANCE … • The subclass differentiates itself from its superclass by the following 2 methods. • It can augment the superclass by adding new fields and new methods. • It override existing behaviours by providing a new implementation of an existing method. Class — A group of similar objects Fields — Properties of a class Objects — Instances of a class Methods — Actions that can be applied on objects Constructor — Action that is used to create an object
  • 110.
    7.0 BENEFITS OFOBJECT ORIENTED PROGRAMMING (OOP) • Object-Oriented Programming is a programming approach which familiars us with the concepts of classes, objects, inheritance, polymorphism, etc. • OOP shows the relationship between the objects, how they relate and how they communicate with each other in order to manipulate data. • It is beneficial in many ways as well as it has countless applications.
  • 111.
    7.0 BENEFITS OFOBJECT ORIENTED PROGRAMMING (OOP) … • Some of the benefits are : OOP makes easier to design the software. It enhances productivity. It’s easy to test, debug, and maintain. It gives the reusability. OOP’s inheritance method helps to lessen the development time OOP coding is more accurate than procedural coding. Hiding and abstraction make the data safe and secure, with less data corruption. • OOP is most demandable because of writing sizeable and composite software.
  • 112.
    7.0 BENEFITS OFOBJECT ORIENTED PROGRAMMING (OOP) … • It is easy to model a real system as real objects are represented by programming objects in OOP. • The objects are processed by their member data and functions. • It is easy to analyze the user requirements. • With the help of inheritance, we can reuse the existing class to derive a new class such that the redundant code is eliminated and the use of existing class is extended. • This saves time and cost of program. • In OOP, data can be made private to a class such that only member functions of the class can access the data. • This principle of data hiding helps the programmer to build a secure program that can not be invaded by code in other part of the program.
  • 113.
    7.0 BENEFITS OFOBJECT ORIENTED PROGRAMMING (OOP) … • With the help of polymorphism, the same function or same operator can be used for different purposes. • This helps to manage software complexity easily. • Large problems can be reduced to smaller and more manageable problems. • It is easy to partition the work in a project based on objects. • It is possible to have multiple instances of an object to co-exist without any interference • i.e. each object has its own separate member
  • 114.
    7.1 APPLICATIONS OFOBJECT ORIENTED PROGRAMMING (OOP) User interface design such as windows, menu. Real Time Systems Simulation and Modeling Object oriented databases AI and Expert System Neural Networks and parallel programming Decision support and office automation
  • 115.
    7.1 APPLICATIONS OFOBJECT ORIENTED PROGRAMMING (OOP) … 1) Real-Time Systems Design • A system is said to be Real-Time if it is required to complete its work and delivers its services on time i.e. Flight Control System etc. • Object-oriented techniques make it easier to control the complexities related to real-time system design. • These techniques give an integrated framework which involves the schedulable analysis and developmental specifications. • It has two main types • Hard Real-Time System: Purely deterministic and 100% time constraint system • i.e. Satellite launching stations, Missile launching stations and Air Bags Controls in cars etc. • Soft Real-Time System: The meeting of the deadline is not compulsory for every time or for every task but the process should be processed and give the result
  • 116.
    7.1 APPLICATIONS OFOBJECT ORIENTED PROGRAMMING (OOP) … 2) Simulation and Modelling System • The varying specification of variables makes it difficult to build complex systems such as ecology, zoology, and agronomic systems. • Modeling and understanding interactions explicitly are required for simulating complex systems. • Object-oriented Programming gives the substitute approach for making these complex modeling systems easier.
  • 117.
    7.1 APPLICATIONS OFOBJECT ORIENTED PROGRAMMING (OOP) … 3) Object-Oriented Database (ODBMS) • The object-oriented database enables us to represent data in the form of objects. • It permits developers to model complex data easily and captures the relationships in a natural way. • It is also known as Object Database Management Systems (ODBMS). • To let the object maintain their identity and integrity, these databases try to balance a relationship between the real-world and database objects. • Identities of objects are identified and operations are then performed on these objects.
  • 118.
    7.1 APPLICATIONS OFOBJECT ORIENTED PROGRAMMING (OOP) … 4) Client-Server System • A client-server is a software structural design model comprises of client systems and server systems, both of which communicate over a computer network or may communicate on the same computer. • Because of object-oriented programming, Client-Server Systems offer the IT infrastructure i.e. operating systems, networks, and hardware, etc., creating object-oriented Client-Server Internet (OCSI) applications. • These applications have three major technologies: The Client Server Object-Oriented Programming The Internet • These models have also structural functionality for email exchange and Web/database access.
  • 119.
    7.1 APPLICATIONS OFOBJECT ORIENTED PROGRAMMING (OOP) … 5) Hypertext, Hypermedia • Hypertext means text augmented with links. • OOP also helps in laying out a framework for Hypertext which is suitable for various media approaches. • Hypertext is basically similar to that of regular text as it can be stored, searched, and edited effortlessly. • The main disparity is that hypertext is text with pointers to other text as well. • Hypermedia is an extension to hypertext that gives facilities like handling sound and video. • It’s a superset of hypertext. • Documents having hypermedia, not only have links to other pieces of text but also to various other forms of media, varies
  • 120.
    7.1 APPLICATIONS OFOBJECT ORIENTED PROGRAMMING (OOP) … 6) Neural Networking And Parallel Programming • It is very useful in addresses the setback of prediction and estimation of complex time- varying systems. • Firstly, the whole time-varying process is divided into numerous time intervals. • Then, neural networks are developed in a specific time interval to scatter the load of several networks. • OOP simplifies the whole process by simplifying the estimation and prediction capability of
  • 121.
    7.1 APPLICATIONS OFOBJECT ORIENTED PROGRAMMING (OOP) … 7) Office Automation Systems • These involve formal and informal electronic systems mainly concerned with information sharing and communication to and from people inside as well as external of the association • i.e. email, Word processing, Web calendars, Desktop publishing, etc.
  • 122.
    7.1 APPLICATIONS OFOBJECT ORIENTED PROGRAMMING (OOP) … 8) CIM (Computer Integrated Manufacturing) / CAD (Computer Aided Design) / CAM (Computer Aided Manufacturing) Systems • OOP can also be used in developing and designing the applications as it allows people to trim down the effort involved. • Such as, it is used in designing blueprints, flowcharts, etc. • OOP makes it easier for the designers and engineers to produce these flowcharts and
  • 123.
    7.1 APPLICATIONS OFOBJECT ORIENTED PROGRAMMING (OOP) … 9) AI Expert Systems • These are computer applications which use databases of expert knowledge to make decisions in many areas as medical diagnosis. • Their advice and decisions are beyond the reach of a human brain as they are reliable, highly responsive and understandable. • There are many more applications of object-oriented programming OOP is widely used in developing and designing applications such as office automation systems etc.