Download - 01 What is OOP
-
7/29/2019 01 What is OOP
1/19
1
Amity School of Engineering
B.Tech., CSE(5th Sem.)
Java Programming
Topic: Object Oriented Programming
ANIL SAROLIYA
Amity School of Engineering & Technology
-
7/29/2019 01 What is OOP
2/19
Text/ Reference Books
JAVA for Beginners, Joyce Farrell, CENGAGE Learning
Java the complete Reference by Patrick Naughton & Herbert Schild, Tata
Mc-Graw Hill Java How to program, Deitel & Deitel, Pearson
Head First Java, Kathy Siera & Bert Bates, OReilly Media
2
Amity School of Engineering & Technology
-
7/29/2019 01 What is OOP
3/19
Home Assignment What do you know about Programming?
What is the role of Compiler & Interpreter in Programming?
What is source code?
What is Class?
What is Object?
What is Object Oriented Programming?
C++ is structured or object oriented programminglanguage. Justify this statement.
Compare Structured and Object Oriented Programming.
What is Encapsulation?
What do you know about Data Abstraction?
What is Inheritance? Also describe (in 2-3 line for each) types of inheritance.
Why the Polymorphism is used in OOP's?
3
Amity School of Engineering & Technology
-
7/29/2019 01 What is OOP
4/19
OOP DefinitionObject-oriented programming is a way of
implementation in which programs are
organized as cooperative collections ofobjects,each of which represents an instance of some
class, and those classes(categories) are all
members of a hierarchy of classes united via
inheritance relationships.''
4
Amity School of Engineering & Technology
-
7/29/2019 01 What is OOP
5/19
New Programming Paradigms Requirement
The cost of software development & maintenance is increasing substantially as
compared to the cost of the hardware of a computing system, but hardware
technology is improved.
This increasing cost in software & technological improvement in hardware demands
a cost effective & more technical compatible programming paradigm.
Software maintenance is the process of modifying or extending the capabilities ofthe existing software.
5
-
7/29/2019 01 What is OOP
6/19
OOPs! a New Paradigm
OOP works on data, with specific methods (functionality) in a bounded
form. Such form is termed as class
To access the class, we need an instance which can create the logicalinterface in between class & user (through main function). Such instance is
termed as Object. That why this new paradigm is termed as Object
Oriented Programming Paradigm
The power of object-oriented languages is that the programmer can create
modular & reusable code which is possible by composition andmodification of the existing modules in a program
6
OOP increasing the flexibility in coding without disturbing the other part of
the code
OOP increasing the software development speedby reusing & enhancing
the existing code
Its reducing the translation burden (from a real-world representation to the
computer-world representation) for the programmer
So, Why OOP?
-
7/29/2019 01 What is OOP
7/19
An object is like a
black box.
Its a material thing
that can be seen or
touched.
The internal details
of such things are
hidden.
OO Programming
Identifying objects and
assigning responsibilities
to these objects.
Objects communicate to
other objects by sending
messages.
Messages are received by
the methods of an object7
Object
What is Object Oriented Programming?
-
7/29/2019 01 What is OOP
8/19
Tangible Things as a car, printer, ...
Roles as employee, boss, ...
Incidents as flight, overflow, ...
Interactions as contract, sale, ...
Specifications as colour, shape,
8
What is an object?
-
7/29/2019 01 What is OOP
9/19
An object represents an individual, identifiable item, unit,or entity, either real or abstract, with a well-defined role
in the problem domain.
Or
An "object" is anything to which a concept applies.
9
What is an object? (continued.)
-
7/29/2019 01 What is OOP
10/19
Modularity - large software projects can be split up insmaller pieces.
Reusability - Programs can be assembled from pre-
written software components.
Extensibility - New software components can be
written or developed from existing ones.
10
Why do we care about objects?
-
7/29/2019 01 What is OOP
11/19
Object = Data + Methodsor
An object has the responsibility to know and
the responsibility to do.
11
= +
The two parts of an object
-
7/29/2019 01 What is OOP
12/19
Features of Object Oriented Programming
12
C++or
Java
-
7/29/2019 01 What is OOP
13/19
Features of OOP Contd
Encapsulation: It is a mechanism that associates the code and the data itmanipulates into a single unit and keeps them safe from external interference and
misuse. Thats why OOP is some how secure than other type of programming.Data Abstraction: The technique ofcreating new data types that are well
suited to an application or program known as data abstraction. It provides the
ability to create user-defined data types which is also known as abstract data
types (ADTs) .
Inheritance: It allows the extension and reuse of existing code without having to rewrite the code
from scratch. Inheritance involves the creation of new classes (derived classes) from the
existing ones (base classes).
It enabling the creation of a hierarchy of classes , which gives the name of relationship:
like: Parent Class & Child Class Relationship
Base Class & Derived Class Relationship
Super Class & Sub Class Relationship
Two popular forms of inheritance are single and multiple inheritance. Single inheritance
refers to deriving a class from a single base class 13
-
7/29/2019 01 What is OOP
14/19
Features of OOP Contd
Multiple Inheritance: A class is derived from more than one base class is
known as multiple inheritance. C++ supports multiple inheritance, JAVA doesn't
Polymorphism: It allows a single name or operator to be associated withdifferent operations depending on the type of data passed to it. It is normally
achieved by function overloading, operator overloading, and dynamic binding
(virtual functions)
Persistence: The incident where the object (data) survives in the program
execution time and exists between executions of a program is known aspersistence. All database systems support persistence. In C++, this is not
supported. However, the user can build it explicitly using file streams in a
program. In Java it is possible.
Delegation: It is an alternative to class inheritance. Delegation is a way of
making object composition as powerful as inheritance. In delegation, twoobjects are involved in handling a request: a receiving object delegates
operations to its delegate. This is analogous to the child classes sending
requests to the parent classes.
Genericity: Genericity is realized through function templates and class
templates. 14
-
7/29/2019 01 What is OOP
15/19
Structured Programming
Emphasis on algorithm rather than data
Programs are divided into individual procedures that perform discrete tasks
Procedures are independent of each other as far as possible
Procedures have their own local data and processing logic
Parameter passing facility between the procedures for information communication
Controlled scope of data
Introduction of the concepts of user defined data types
Support for modular programming (used to break up a large program into manageable units),
projects can be broken up into modules and programmed independently
Scope of data items is further controlled across modules
A rich set of control structures are available to further abstract the procedures
Examples: Pascal and C
15
Limitations: Co-ordination among multiple programmers is required for
handling the changes made to mutually shared data items
Maintenance of a large software system is tedious and costly
-
7/29/2019 01 What is OOP
16/19
Object Oriented Programming
Depending on the object features supported, the languages are classified into two
categories:
1. Object-Based Programming Languages
2. Object-Oriented Programming LanguagesObject-based language = Encapsulation + Object Identity(means Object Name)
&
Object-oriented language = Object based language features + Inheritance
+Polymorphism
16
Features of OOPSImprovement over the structured programming paradigm
Emphasis on data rather than algori thm
Data abstraction is introduced in addition to procedural abstraction
Data and associated operations are un if ied in to a single unit which is termed as Object
Programs are designed around the data being operated, rather than operationsthemselves (data decomposition-rather than algorithmic decomposition)
Relationships can be created between similar, yet distinct data types
Examples: Java, C++, Smalltalk, Eiffel. etc.
-
7/29/2019 01 What is OOP
17/19
Structured Versus Object-Oriented Programming
17
In structured programming orconventional
programming or function oriented
programming orprocedural programming,
data are defined as global data and access
(or changes) by all the functions of a
program without any restriction . Due to
this data security and integrity has
reduced
whereas,
OOPs, data is encapsulated with the
associated functions (or operations),
such encapsulated formorcapsuleiscalled an object
-
7/29/2019 01 What is OOP
18/19
Structured Versus Object-Oriented Programming (contd..)
18
In the OO approach. the problem is divided into objects
whereas
In FOP the problem is divided into functions
Both approaches adopt the same philosophy of divide and conquer,
but , OOP conquers a bigger region,While, FOP is conquering a smaller region
Hence, OOP contains FOPand so OOP can be referred to as the super set of FOP
(like C++. which is a superset of C)
Unlike traditional languages, OO languages allow localization of data and code and restrict other
objects from referring to its local region [see the object figure (in previous slide)]For this, OOP is centered around the concepts of objects, such as:
Encapsulations,
Abstract data types,
Inheritance,
Polymorphism,
Message based communication, etc.
During the execution of a program, the objects interact with each other by sending messages and
receiving responses.
For Example, in a program to perform withdrawals from an account, a customer object can send a
withdrawal message to a bank account object.
Means, An object communicating with other objects need not be aware of the internal work ing of
the objects with which i t interacts.
-
7/29/2019 01 What is OOP
19/19
Thanks
19
Amity School of Engineering & Technology
B.Tech., CSE(5th Sem.)