Anda di halaman 1dari 19

Amity School of Engineering & Technology

Amity School of Engineering


B.Tech., CSE(5th Sem.)

Java Programming Topic: Object Oriented Programming ANIL SAROLIYA

Amity School of Engineering & Technology

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

Amity School of Engineering & Technology

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 programming language. 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?

Amity School of Engineering & Technology

OOP Definition
Object-oriented programming is a way of implementation in which programs are organized as cooperative collections of objects, 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.''

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 of 5 the existing software.

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 logical interface 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 and modification of the existing modules in a program

So, Why OOP?


OOP increasing the flexibility in coding without disturbing the other part of the code OOP increasing the software development speed by reusing & enhancing the existing code Its reducing the translation burden (from a real-world representation to the computer-world representation) for the programmer
6

What is Object Oriented Programming?

Object

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 object
7

What is an object?
Tangible Things Roles Incidents Interactions Specifications as a car, printer, ... as employee, boss, ... as flight, overflow, ... as contract, sale, ... as colour, shape,

What is an object? (continued.)


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.

Why do we care about objects?


Modularity - large software projects can be split up in smaller pieces. Reusability - Programs can be assembled from prewritten software components. Extensibility - New software components can be written or developed from existing ones.

10

The two parts of an object

Object = Data + Methods or An object has the responsibility to know and the responsibility to do.

11

Features of Object Oriented Programming

C++ or Java

12

Features of OOP Contd


Encapsulation: It is a mechanism that associates the code and the data it
manipulates 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 of creating 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

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 with different 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 as persistence. 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, two objects 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

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

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

15

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 Languages Object-based language = Object-oriented language = Encapsulation &

+ Object Identity(means Object Name) + Inheritance

Object based language features

+
Features of OOPS
Polymorphism

Improvement over the structured programming paradigm Emphasis on data rather than algorithm Data abstraction is introduced in addition to procedural abstraction Data and associated operations are unified into a single unit which is termed as Object Programs are designed around the data being operated, rather than operations themselves (data decomposition-rather than algorithmic decomposition) Relationships can be created between similar, yet distinct data types Examples: Java, C++, Smalltalk, Eiffel. etc.

16

Structured Versus Object-Oriented Programming


In structured programming or conventional programming or function oriented programming or procedural 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 form or capsule is called an object

17

Structured Versus Object-Oriented Programming (contd..)


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 FOP and 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 working of the objects with which it interacts.
18

Amity School of Engineering & Technology B.Tech., CSE(5th Sem.)

Thanks
19

Anda mungkin juga menyukai