0% found this document useful (0 votes)
12 views

Unit-1 OOPM

Uploaded by

Lucky Saxena
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
12 views

Unit-1 OOPM

Uploaded by

Lucky Saxena
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 47

Acropolis Institute of Technology &

Research, Indore
www.acropolis.in
Object Oriented Programming and
Methodology (AL305)

By: Ms.Lucky Saxena


Unit-1
Introduction to Object Oriented
Programming
What is Program?
• A computer program is a set of step by step instructions that tell a computer what to do.
• These instructions are grouped together to accomplish a task or tasks.
• In another words we can say a program is a set of ordered instructions that enable a computer to
carry out a specific task
• Everything done on a computer is done by using a computer program.

March 27, 2024 4 Slide No.- 1


What is Programming?
• Programming is a way to “instruct the computer to perform various tasks”.
• We provide a set of instructions to computer that are written in a language that the computer can
understand.
• This language is called programming language.
• Some of the popular Programming languages are Python, C, C++, Java, etc.

March 27, 2024 5 Slide No.- 1


Hierarchy of Programming Paradigms

March 27, 2024 6 Slide No.- 1


Introduction to Object Oriented Programming?

With the help of object orientation, we can design new objects using existing objects.

It is useful to analyze the business policy, practices and operations.

Object oriented programming approach removes the flaws of the procedure oriented
programming approach.

It is the most recent concept among programming paradigms.

Slide No.
March 27, 2024 7
Introduction to Object Oriented Programming

 Object oriented programming is a way of thinking about problems using real world
concept.

The fundamental construct is the object which combines data and functions together.

Up to now, some of the programs we have been writing use a procedural
programming paradigm.

In procedural programming the focus is on writing functions or procedures which


operate on data.

Slide No.
March 27, 2024 8
Introduction to Object Oriented Thinking
 In object-oriented programming the focus is on the creation of
objects which contain both data and functions together.

Usually, each object definition corresponds to some object or


concept in the real world and the functions that operate on that
object correspond to the ways real-world objects interact.

Slide No.
March 27, 2024 9
Object Oriented Programming?
 Object oriented programming has been developed to
overcome the limitations of procedural programming.

New features of object oriented programming are helpful in


the development of well designed software applications.

In object oriented paradigm, each object is represented by


information.

When objects interact, some information would change and


some information may not be affected.
March 27, 2024
Slide No.
10
Object Oriented Programming?
 Object Oriented Programming organizes data and functions as
follows:

Fig.: Object Oriented Paradigm Slide No.


March 27, 2024 11
Why do we need Object Oriented Programming?
Object Oriented Programming was developed because some
limitations were found in traditional programming languages for
example:

1. Functions have unrestricted access to global data.


2. Unrelated function and data provide a poor model of real
world.
3. Program structure is difficult to conceptualize.
4. It was difficult to modify programs i.e. a change made in
global data may result in rewriting all the functions that
access them.
March 27, 2024
Slide No.
12
Applications of Object Oriented Programming
Applications of OOP are beginning to gain importance in many areas. Its areas
of application are:
• Object oriented databases
• Office automation systems.
• Parallel programming.
• Artificial Intelligence.
• Computer Aided Designing and Computer Aided Manufacturing systems.
• Real-time systems and Neural networks.
• Simulation and modeling
• Expertext, hypermedia and hypertext.
• Decision support systems and Expert systems.
Slide No.
March 27, 2024 13
Characteristics of POP
• Emphasis is on algorithms.
• Large programs are divided into smaller programs known as
functions
• Data move openly around the system from one function to another.
• Functions transform data from one form to another.

March 27, 2024 14


Characteristics of OOP
• Emphasis is on data rather than procedure.
• Programs are divided into objects.
• Data is hidden and cannot be used by external functions.
• Objects may communicate with each other through functions.
• New data and function can be added whenever necessary.

March 27, 2024 15


POP and OOP
POP (stands for Procedure Oriented Programming)

It is Known as Procedural Oriented Programming Language.


It is defined as programming approach that focuses on procedures and functions. Ex-C.

OOP (stands for Procedure Oriented Programming)

It is Known as Object Oriented Programming Language.


It is defined as programming approach that focuses on data rather than the algorithm.

Slide No.
March 27, 2024 16
Difference between OOP with POP

March 27, 2024 17


Comparison of C and C++
S. No. C C++
1 C++ was developed by Bjarne
C was developed by Dennis Ritchie in
Stroustrup in 1979 at AT&T Bell Labs
1972 at AT&T Bell Labs ..
USA.
2 C is a subset of C++. C++ is a superset of C. C++ can run
most of C code while C cannot run C++
code.
3 C is Procedural Language. C++ is Object oriented Language.
4 C is a function driven language. C++ is an object driven language.
5 C uses functions i.e. scanf and printf for C++ uses objects i.e. cin and cout for input
input and output. and output.
6 In C, top down approach is used in In C++, bottom up approach is used in
Program Design. Program Design.
7 C requires all the variables to be C++ allows the declaration of variable
declared at the starting of a scope. anywhere in the scope i.e at time of its
first use.
8 In C, malloc() and calloc() functions
In C++, new operators is used for
are used for memory allocation and
memory allocation and delete operator
free() function is used for memory de-
is used for memory de-allocation.
allocation.
9 In C, Exception Handling is not In C++, Exception Handling is done
available. with try and catch blocks.
10 C has no support for: C++ supports:
Information Hiding, Information Hiding,
Data Encapsulation, Data Encapsulation,
Polymorphism, Polymorphism,
Inheritance, Inheritance,
Function and Operator Overloading, Function and Operator Overloading,
Virtual Function Virtual Function
Reference Variables etc. Reference Variables etc.
March 27, 2024 18
cout and cin

• Statement cout<<”Object Oriented Programming”; causes this to be displayed on


the computer screen.

• Here identifier cout (pronounced “C out”) is actually a predefined object in C++.

• It is an object of ostream class. Here stream refers to the flow of data.

• The standard output stream normally flows to the screen display and can be
redirected to other output devices.

March 27, 2024 19


cout

March 27, 2024 20


cin

• The identifier cin (pronounced “C in”) is actually a predefined object in C++.


• It is an object of istream class.
• This object corresponds to the standard input stream.
• This stream refers to the flow of data coming from the keyboard.
• It takes the value from the stream object on its left and places it in the variable on its
right.

March 27, 2024 21


cin

March 27, 2024 22


Data Types
• Data type specifies type of a variable being used in a program.
• A variable needs to be declared using appropriate data type before it is being used.
• C++ supports following data types:

March 27, 2024 23


Data Types

March 27, 2024 24


Type Conversion

 When variables of one type are mixed with variables of another type, a type conversion
will occur.

 C++ performs the conversion automatically.

 This process is known as automatic or implicit type conversion or type promotion.

 Compiler simply follows the rule that “the smaller” type is converted to the “wider”
type.

March 27, 2024 25


Type Conversion

March 27, 2024 26


Type Conversion

March 27, 2024 27


Features of Object Oriented Programming
• Significant features of Object Oriented Programming are:

• OOP follows bottom-up programming approach in program design.

• Programs are divided into objects (objects are instances of the


class).

• Emphasis is on data rather than procedure.

March 27, 2024 28


Features of Object Oriented Programming Cont..
• Data is hidden and cannot be accessed by external functions.

• Functions that operate on the data of an object are tied together in


the data structure.

• Objects may communicate with each other through functions.

• Data structures are designed to characterize the objects.


• New data and functions can be easily added whenever required.
March 27, 2024 29
Merits of OO Methodology
1. Improved software-development productivity:
• Object-oriented programming is modular, as it provides separation of
duties in object-based program development.

• Because of three factors – modularity, extensibility, and reusability –


object-oriented programming provides improved software-
development productivity over traditional procedure-based
programming techniques.

March 27, 2024 30


Merits of OO Methodology Cont…
2. Improved software maintainability: Since the design is modular,
part of the system can be updated in case of issues without a need to
make large-scale changes.

3. Faster development: Reuse enables faster development. Object-


oriented programming languages come with rich libraries of objects,
and code developed during projects is also reusable in future
projects.

March 27, 2024 31


Merits of OO Methodology Cont…
4. Lower cost of development: The reuse of software also lowers the
cost of development. Typically, more effort is put into the object-
oriented analysis and design, which lowers the overall cost of
development.

5. Higher-quality software: Faster development of software and


lower cost of development allows more time and resources to be
used in the verification of the software.

March 27, 2024 32


De-Merits of OO Methodology
• Sometimes the relation among the classes become artificial in nature.
• The OOP design is tricky and requires appropriate knowledge. Also,
one needs to do proper planning and design for OOP programming.
• To program with OOP, the programmer needs proper skills such as
that of design, programming and thinking in terms of objects and
classes etc.
• It needs more memory to store the objects, instance.

March 27, 2024 33


Object Oriented Programming Languages
Various Object Oriented Programming Languages are:

• C++
• Java
• Simula
• Smalltalk
• Eiffel
• Modula-3
• Self

Slide No.
March 27, 2024 34
Elements of OOPs
1. Class
2. Object
3. Inheritance
4. Data Abstraction
5. Data Hiding
6. Encapsulation
7. Polymorphism
8. Message Passing

Slide No.
March 27, 2024 35
Class
• Class is a user-defined data type.
• A class is like a blueprint for an object.
• It is a logical entity.
• Class is collection of objects of similar type.

Slide No.
March 27, 2024 36
Objects
• This is the basic unit of object oriented programming. That is both data and
function that operate on data are bundled as a unit called as object.
• An object can be defined as an instance of class and there can be multiple
instance of a class in a program.
• An object is a real world entity.
• An object has state and behavior.
object- stud
data – name, rollno., class
function – display, getdata

Slide No.
March 27, 2024 37
Objects
Example of object

Following kind of things can become objects in object oriented programming:

• A person e.g. student or customer


• A place e.g. Indore or Delhi
• A bank account
• A table of data
• Any item that the program has to handle
• Any user defined data e.g. list
Slide No.
March 27, 2024 38
Inheritance
• One of the most useful aspects of object-oriented programming is code
reusability.
• Inheritance is the process of forming a new class from an existing class that
means it acquire the property and behavior of existing class in new class.
• It is like parent-child relationship.

Slide No.
March 27, 2024 39
Abstraction
• Data abstraction refers to providing only essential information about the data to
the outside world.
• Hiding the background details or implementation and represents only needed
information to outside world.
• Consider a real-life example: A man driving a car. The man only knows that
pressing the accelerators will increase the speed of the car or applying brakes will
stop the car but he does not know about its internal mechanism.

Slide No.
March 27, 2024 40
Data Hiding
• It is software development technique specifically used in object-oriented
programming.
• It hides the internal object details.
• It also reduces system complexity to increase robustness.
• Example - By declaring the member variables and functions as a private in a
class, the members are hidden from outside the class. Those private members and
data cannot be accessed by the object directly.

Slide No.
March 27, 2024 41
Encapsulation
• Encapsulation is defined as binding together the data and the functions that
manipulate them.

Slide No.
March 27, 2024 42
Polymorphism
• Polymorphism is the ability of a function or operator to act in different forms
depending on the place they are used.
• One task is performed by different ways.
• Ex: A person at the same time can have different characteristics. Like a man at the
same time is a father, a bother ,an employee. So the same person posses different
behavior in different situations. This is called polymorphism.

Slide No.
March 27, 2024 43
Polymorphism
Types of Polymorphism
There are two types of Polymorphism available in C++
•Compile Time Polymorphism
•Run Time Polymorphism

Slide No.
March 27, 2024 44
Dynamic Binding
Binding refers to the linking of a procedure call to the code to be executed in
response to the call.

Dynamic binding means that the code associated with a given procedure is not
known until the time of the call at run-time.

Choosing functions during execution time is called dynamic binding.

Slide No.
March 27, 2024 45
Message Passing
• It is a form of communication between the objects
• Objects communicate with one another by sending and receiving information to
each other.
• A message for an object is a request for execution of a procedure and therefore
will invoke a function in the receiving object that generates desired results.

Slide No.
March 27, 2024 46
THANKS
March 27, 2024 47

You might also like