1 Intro to OOP
1 Intro to OOP
• Programming:
and imagination.
1
Contd…
• Program:
a certain task.
– E.g.,
• Prepare coffee
2
Contd…
• Programming language:
3
Contd…
• Classification Of Programming Languages:
– Machine Language:
• use 0 and 1 to express the instructions
– Assembly Language:
• This language uses mnemonics to express the instructions
– High-level language:
• This language uses human understandable like language
to express the instructions
4
Contd..
5
Programming Paradigms
• Program organizing principles are called programming
paradigms.
– Unstructured programming
– Procedural programming
– Structured programming
– Object-oriented programming
– Object-based programming
6
Contd…
• Unstructured Programming paradigm:
one program.
7
Contd…
• This programming technique provides tremendous
disadvantages (duplicacy and redundancy of code, code
maintenance problem, readability and many more ) once the
program gets sufficiently large
• For example, if the same statement sequence is needed at
different locations within the program, the sequence must be
copied.
• This has lead to the idea of extracting these sequences, naming
them and offering a technique to call and return from these
procedures. i.e., Reuse the same code at different places in the
program without copying it.
8
Contd…
• Procedural Programming:
– Combine returning sequences of statements
into one single place
9
Contd…
• With the introduction of parameters as well as procedures of procedures ( sub-
procedures) programs can now be written more structured and error free
– For example, if a procedure is correct, every time it is used it produces correct results
• The main program is responsible to pass data to the individual calls, the data is
processed by the procedures and, once the program has finished, the resulting
data is presented
10
Contd…
• Now we have a single program which is divided into small
pieces called procedures
11
Contd…
• Structured Programming (Modular Programming) Paradigm:
– During the 1970s it became clear that even well-structured programs were
not enough for mastering the complexity involved in developing a large
program system
– It was also recognized that it was necessary to support the division of the
program into well-defined parts or modules, that could be developed and
tested independently of one another, so that several people could work
together within one large programming project
12
Contd…
• With modular programming procedures of a common
functionality are grouped together into separate modules
• Each module can have its own data. This allows each module to manage an
14
Contd…
Unstructured, procedural, modular programming
Unstructured programming.
Procedural programming.
The main program directly
The main program
operates on global data
coordinates calls to Modular programming. The main
procedures and hands over program coordinates calls to
appropriate data as parameters procedures in separate modules
and hands over appropriate data
as parameters
15
Contd…
• Features of structured programming:
function.
16
Contd…
• Advantages of structured programming: The
programming.
– Reduced complexity
– Increased productivity
– Portability
17
Contd…
• Problems with structured programming: Some
– Data under-valued
18
Contd…
• Complexity of managing large projects:
19
Contd…
• Data Undervalued:
procedural languages.
functions access the same global data, the way the data is
20
Contd…
• Relationship to the Real World:
21
Contd…
• New Data Types:
maintain.
23
Characteristics(features) of object oriented languages:
– Objects
– Classes
– Inheritance
24
Contd…
• Objects:
– Objects are the basic run- time entities in an object-oriented program.
– They may represent a person, place, table etc. They are identified by its
unique name.
instance.
– Each object contains data and code to manipulate the data. So, they occupy
space in memory.
25
26
Contd…
• Classes:
– Collection of objects is called class. It is a logical
entity. So, it does not occupy space.
27
28
29
Contd…
• Abstraction:
– Abstraction means the representation of the essential
features without providing the internal details and
complexities. i.e. give input get output is only
concern
• For example: phone call, we don't know the internal
processing.
31
Contd…
• Encapsulation:
– Encapsulation is the process of combining the data (called
fields or attributes) and functions (called methods or
behaviors) into a single framework called class.
– Encapsulation helps prevent the modification of data
from outside the class by properly assigning the access
privilege to the data inside the class.
– So the term data hiding is possible due to the concept of
encapsulation, since the data are hidden from the outside
world.
32
33
Contd…
• Inheritance:
– Inheritance is the process of acquiring certain
attributes and behaviors from parents.
• For examples, cars, trucks, buses, and motorcycles inherit
all characteristics of vehicles.
34
35
36
Contd…
– Object-oriented programming allows classes to inherit
commonly used data and functions from other classes.
37
Contd…
• Polymorphism and Overloading
• Operator overloading
39
40
41
Contd…
• Advantages of OOPs:
– Code recycle and reuse.
42
Contd…
• Disadvantages of OOPs:
methodology.
43
Structured Programming Object Oriented Programming
Structured Programming is designed which Object oriented programming is designed
focuses on procedure and then data which focuses on data.
required for that procedure.
Structured programming is also known Object oriented programming
as modular Programming and a subset supports inheritance, encapsulation,
of procedural programming language. abstraction, polymorphism, etc.
In structured programming, programs are In Object oriented programming, Programs
divided into small self contained functions. are divided into small entities
called objects.
Structured programming is less secure as Object oriented programming is more
there is no way of data hiding. secure as having data hiding feature.
Structured programming can Object oriented programming can solve
solve moderately complex programs. any complex programs.
Structured programming Object oriented programming provides
provides less reusability, more function more reusability, less function dependency.
dependency.
Less abstraction and less flexibility. More abstraction and more flexibility.
44
Assignment-1
1. Explain characteristics and limitations of procedural programming?
45
End of Unit 1
Thank You !
46