Object Oriented Programming

Slides:



Advertisements
Similar presentations
Final and Abstract Classes
Advertisements

Understand and appreciate Object Oriented Programming (OOP) Objects are self-contained modules or subroutines that contain data as well as the functions.
Classes and Object- Oriented... tMyn1 Classes and Object-Oriented Programming The essence of object-oriented programming is that you write programs in.
Object-Oriented PHP (1)
Inheritance and Class Hierarchies Chapter 3. Chapter 3: Inheritance and Class Hierarchies2 Chapter Objectives To understand inheritance and how it facilitates.
Fall 2007CS 2251 Inheritance and Class Hierarchies Chapter 3.
OOP in Java Nelson Padua-Perez Chau-Wen Tseng Department of Computer Science University of Maryland, College Park.
1 Introduction to C++ Programming Concept Basic C++ C++ Extension from C.
WEL COME PRAVEEN M JIGAJINNI PGT (Computer Science) MCA, MSc[IT], MTech[IT],MPhil (Comp.Sci), PGDCA, ADCA, Dc. Sc. & Engg.
OOP in Java Fawzi Emad Chau-Wen Tseng Department of Computer Science University of Maryland, College Park.
C++ fundamentals.
OBJECT ORIENTED PROGRAMMING
OBJECT ORIENTED PROGRAMMING IN C++ LECTURE
C++ Object Oriented 1. Class and Object The main purpose of C++ programming is to add object orientation to the C programming language and classes are.
Learners Support Publications Pointers, Virtual Functions and Polymorphism.
Object Oriented Programming Development
Introduction to Object-oriented programming and software development Lecture 1.
GENERAL CONCEPTS OF OOPS INTRODUCTION With rapidly changing world and highly competitive and versatile nature of industry, the operations are becoming.
Introduction to Object Oriented Programming. Object Oriented Programming Technique used to develop programs revolving around the real world entities In.
Recap (önemli noktaları yinelemek) from last week Paradigm Kay’s Description Intro to Objects Messages / Interconnections Information Hiding Classes Inheritance.
Features of Object Oriented Programming Lec.4. ABSTRACTION AND ENCAPSULATION Computer programs can be very complex, perhaps the most complicated artifact.
Object Oriented Programming with C++/ Session 6 / 1 of 44 Multiple Inheritance and Polymorphism Session 6.
CHAPTER 3 Function Overloading. 2 Introduction The polymorphism refers to ‘one name having many forms’ ‘different behaviour of an instance depending upon.
Guided Notes Ch. 9 ADT and Modules Ch. 10 Object-Oriented Programming PHP support for OOP and Assignment 4 Term project proposal C++ and Java Designer.
CS212: Object Oriented Analysis and Design Lecture 9: Function Overloading in C++
OOP: Encapsulation,Abstraction & Polymorphism. What is Encapsulation Described as a protective barrier that prevents the code and data being randomly.
C++ Programming Basic Learning Prepared By The Smartpath Information systems
Introduction to c++ programming - object oriented programming concepts - Structured Vs OOP. Classes and objects - class definition - Objects - class scope.
Abstraction ADTs, Information Hiding and Encapsulation.
Programming Paradigms Lecturer Hamza Azeem. What is PP ? Revision of Programming concepts learned in CPLB Learning how to perform “Object-Oriented Programming”
Inheritance. Inheritance - Introduction Idea behind is to create new classes that are built on existing classes – you reuse the methods and fields and.
9-Dec Dec-15  INTRODUCTION.  FEATURES OF OOP.  ORGANIZATION OF DATA & FUNCTION IN OOP.  OOP’S DESIGN.
Programming With Java ICS201 University Of Ha’il1 Chapter 7 Inheritance.
Object Oriented Programming
UMass Lowell Computer Science Java and Distributed Computing Prof. Karen Daniels Fall, 2000 Lecture 9 Java Fundamentals Objects/ClassesMethods Mon.
1 COSC2007 Data Structures II Chapter 9 Class Relationships.
Inheritance CSI 1101 Nour El Kadri. OOP  We have seen that object-oriented programming (OOP) helps organizing and maintaining large software systems.
Introduction to Object-Oriented Programming Lesson 2.
WEL COME PRAVEEN M JIGAJINNI PGT (Computer Science)
Inheritance and Class Hierarchies Chapter 3. Chapter 3: Inheritance and Class Hierarchies2 Chapter Objectives To understand inheritance and how it facilitates.
Inheritance and Class Hierarchies Chapter 3. Chapter Objectives  To understand inheritance and how it facilitates code reuse  To understand how Java.
Classes, Interfaces and Packages
1 CSE Programming in C++. 2 Overview Sign roster list Syllabus and Course Policies Introduction to C++ About Lab 1 Fill Questionnaire.
Copyright 2005, The Ohio State University CSE – Introduction to C++ Name: Shirish Tatikonda Time: T 3:30 PM Room: BE 394
Recap Introduction to Inheritance Inheritance in C++ IS-A Relationship Polymorphism in Inheritance Classes in Inheritance Visibility Rules Constructor.
Author: DoanNX Time: 45’.  OOP concepts  OOP in Java.
OOPS CONCEPT.  OOPS  Benefits of OOPs  OOPs Principles  Class  Object Objectives.
Structure A Data structure is a collection of variable which can be same or different types. You can refer to a structure as a single variable, and to.
COMPUTER SCIENCE & TECHNOLOGY DEGREE PROGRAMME FACULTY OF SCIENCE & TECHNOLOGY UNIVERSITY OF UVA WELLASSA ‏ Properties of Object Oriented Programming.
1 C++ Classes & Object Oriented Programming Overview & Terminology.
Welcome to FUNCTION OVERLOADING Prepared By Prepared By : VINAY ALEXANDER ( विनय अलेक्सजेंड़र ) PGT(CS) KV jhagrakhand.
Welcome to OBJECT ORIENTED PROGRAMMING Prepared By Prepared By : VINAY ALEXANDER PGT(CS) KV jhagrakhand.
Object-oriented programming (OOP) is a programming paradigm using "objects" – data structures consisting of data fields and methods together with their.
Modern Programming Tools And Techniques-I
Programming paradigms
Object-Oriented Programming Concepts
Function Overloading.
OOP What is problem? Solution? OOP
Review: Two Programming Paradigms
INTRODUCTION TO OBJECT-ORIENTED PROGRAMMING (OOP) & CONCEPTS
PRINCIPALES OF OBJECT ORIENTED PROGRAMMING
Object Oriented Analysis and Design
WEL COME PRAVEEN M JIGAJINNI PGT (Computer Science)
Object-Oriented Programming
Week 6 Object-Oriented Programming (2): Polymorphism
Object-Oriented Programming
Object-Oriented Programming
Object-Oriented PHP (1)
C++ Object Oriented 1.
Computer Science II for Majors
Presentation transcript:

Object Oriented Programming INTRODUCTION : The object oriented programming paradigm is the latest in the software development and the most adopted one in the developing projects of today. Paradigm means organizing principle of a program. It is an approach to programming.

Procedural V/s Object Based Programming In procedural programming, whenever the definition of type changes, the functions referring to this type must also be changed to reflect the change. Procedural programming leads to increased time and cost overheads during design changes. In object based programming, whenever there is any change in the definition of type,user’s interface remains unaffected generally. Object based programming is subset of OOP. Because it implements some of the features of OOP.

OOP -Concepts Data Abstraction – it is the act of representing the essential features without including the background details. Data Hiding- it is a related concept of data abstraction. Unessential features are hidden from the world. Data Encapsulation – it is the wrapping of data and associated functions in one single unit. Inheritance – it is the capability of one class to inherit properties from other class. Polymorphism – it is the ability for data to be processed in more than one form. Modularity – it is the concept of breaking down the program into several module. E.g. : Classes, Structure, etc.

Implementing OOP concepts in C++ We know that a class represents a group of objects that share common properties and relationship. While an object is a distinct instance of a given class that has some characteristics and behavior. While implementing encapsulation the following things are taken care of – (i) Anything that an object does not know or cannot do is excluded from the object. (ii) Encapsulation is used to hide unimportant implementation details from other objects. (iii) Packaging an object’s variables within the protective custody is accomplished through classes i.e.the data and associated functions are wrapped up in one unit .

Implementing OOP concepts in C++ A class groups its members into three sections: private, protected and public. The private and protected members remain hidden from outside world. Thus through private and protected members , a class implements data-hiding. The outside world is given only the essential and necessary information through public members, rest of the things remain hidden, which is nothing but abstraction. As abstraction means representation of essential features without including the background details.

Implementing OOP concepts in C++ Inheritance is implemented in C++ by specifying the name of the (base) class from which the class being defined (the derived class) has to inherit from.The class which is inherited is called the base class or super class. And class which inherits from other class is called derived class or sub class. In C++ an Abstract Class is the one, which defines an interface, but does not necessarily provide implementations for all its member functions. An abstract class is meant to be used as the base class from which other classes are derived. The derived class is expected to provide implements for the member functions that are not implemented in the base class. A derived class that implements all the missing functionality is called a Concrete Class. A concrete class derives from its abstract class.

Implementing OOP concepts in C++ Polymorphism is implemented through virtual functions,overloaded functions and overloaded operators. A virtual function is used to specify the interface in abstract class. The term ‘overloaded function' refers to a function having more than one distinct meanings. The term ‘overloaded operator’ is used when more than one meaning are defined for an operator.

Function Overloading A function name having several definitions that are differentiable by the number or types of their arguments, is known as an overloaded function and this process is known as Function Overloading. Function overloading is needed in order to simulate real world objects in programming. Function overloading not only implements polymorphism but also reduces number of comparisons in a program and thereby makes the program run faster. The key to function overloading is a function’s argument list which is also known as the function’s signature. If two functions are having same number and types of arguments in the same order , they are said to have the same signature.

Function Overloading Let us take an example to understand the process of function overloading- The following code overloads a function area to compute areas of circle,rectangle and triangle. float area (float radius) { return (3.14*radius*radius); } float area (float length , float breadth ) return (length*breadth); float area (float side1,float side2, float side3) float s = (side1+side2+side3) /2; float ar = sqrt (s*(s-side1) * (s-side2) * (s-side3) ); return ar ;

Restrictions on Overloaded Functions Any two functions in a set of overloaded functions must have different argument lists. Overloading functions with argument lists of the same types, based on return type alone, is an error. Member functions cannot be overloaded solely on the basis of one being static and the other non static. Typedef declarations do not define new types; they introduce synonyms for existing types. They do not affect the overloading mechanism.

Calling overloaded functions Overloaded functions are called just like other functions. The number and type of arguments determine which functions should be invoked. A function call first matches the prototypes available with the number and type of arguments provided with the function call and then calls the appropriate function for execution. But sometimes there might be ambiguity between float and double values or say int or long values. For instance if we want to invoke the function with the following declaration – void prnsqr (double d); with the value 1.24. This value may also be assumed to be float as well as double. Now to avoid such ambiguity, we can use constant suffixes (F,L,U, etc.) to distinguish between such values. For instance the suffix F (312.32F) makes it a float.

Steps involved in finding the best match A call to an overloaded function is resolved to a particular instance of the function through a process known as argument matching, which can be termed as a process of disambiguation. Argument matching involves comparing the actual arguments of the call with the formal arguments of each declared instance of the function. There are three possible cases , a function call may result in: (a) A match – a match is found for the function call. (b) No match – No match is found for the function call. (c) Ambiguous Match – More than one defined instance match for the function call.

Steps involved in finding the best match-2 Search for an Exact Match– if the type of the actual argument exactly matches the type of one defined instance, the compiler invokes that particular instance . For example – void afunc (int); // overloaded functions void afunc (double); afunc (0) ; // exact match . Matches afunc (int) 0 (Zero) is of type int , thus the exactly matches afunc (int) A match through promotion or conversion rules – if no exact match is found, an attempt is made to achieve a match through promotion of the actual argument. i.e. by conversion of data types. As char ,short can be converted into int data type and float can be converted into double.

Advantage of OOP Re –Use of code- In OOP objects allows related objects to share code.Encapsulation allows class definitions to be re-used in other applications. Ease of Comprehension – The classes can be set up to closely represent the generic application concepts and processes. OOP codes are more near to real-world models than other programming methodologist's codes. Ease of fabrication and maintenance – The concepts such as encapsulation data abstraction allow for very clean designs. Easy redesign and extension – The same concepts facilitate easy redesign and extension.

Assignments How are classes and objects implemented? Discuss the relation between abstract and concrete classes. What is polymorphism ? How does function overloading implement polymorphism ? What do you understand by Data Encapsulation and Data Hiding? Also give an example to illustrate both.