OBJECT ORIENTED PROGRAMMING

Slides:



Advertisements
Similar presentations
Object Oriented Programming
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.
Object-oriented Programming Concepts
1 Introduction to C++ Programming Concept Basic C++ C++ Extension from C.
Chapter 10 Classes Continued
WEL COME PRAVEEN M JIGAJINNI PGT (Computer Science) MCA, MSc[IT], MTech[IT],MPhil (Comp.Sci), PGDCA, ADCA, Dc. Sc. & Engg.
INTRODUCTION TO JAVA PROGRAMMING Chapter 1. What is Computer Programming?
C++ fundamentals.
OBJECT ORIENTED PROGRAMMING IN C++ LECTURE
Programming Languages and Paradigms Object-Oriented Programming.
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.
Object Oriented Programming Development
Introduction to Object-oriented programming and software development Lecture 1.
MT311 Java Application Development and Programming Languages Li Tak Sing( 李德成 )
Welcome to OBJECT ORIENTED PROGRAMMIN Date: 10/09/2014 Prepared By Prepared By : VINAY ALEXANDER PGT(CS) KV jhagrakhand.
Lecture 8 Inheritance Richard Gesick. 2 OBJECTIVES How inheritance promotes software reusability. The concepts of base classes and derived classes. To.
CONCEPTS OF OBJECT ORIENTED PROGRAMMING. Topics To Be Discussed………………………. Objects Classes Data Abstraction and Encapsulation Inheritance Polymorphism.
CHAPTER 3 Function Overloading. 2 Introduction The polymorphism refers to ‘one name having many forms’ ‘different behaviour of an instance depending upon.
Copyright 2003 Scott/Jones Publishing Standard Version of Starting Out with C++, 4th Edition Chapter 13 Introduction to Classes.
Learners Support Publications Classes and Objects.
CS212: Object Oriented Analysis and Design Lecture 9: Function Overloading in C++
C++ Programming Basic Learning Prepared By The Smartpath Information systems
1 Programming Paradigms Object Orientated Programming Paradigm (OOP)
Introduction to c++ programming - object oriented programming concepts - Structured Vs OOP. Classes and objects - class definition - Objects - class scope.
Learners Support Publications Object Oriented Programming.
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”
9-Dec Dec-15  INTRODUCTION.  FEATURES OF OOP.  ORGANIZATION OF DATA & FUNCTION IN OOP.  OOP’S DESIGN.
Object Oriented Programming
Introduction to Object-Oriented Programming Lesson 2.
نظام المحاضرات الالكترونينظام المحاضرات الالكتروني Introduction to Object Oriented Programming (OOP) Object Oriented programming is method of programming.
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.
Object Oriented Programming. OOP  The fundamental idea behind object-oriented programming is:  The real world consists of objects. Computer programs.
Author: DoanNX Time: 45’.  OOP concepts  OOP in Java.
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.
Inheritance Modern object-oriented (OO) programming languages provide 3 capabilities: encapsulation inheritance polymorphism which can improve the design,
INTRODUCTION TO OBJECT-ORIENTED PROGRAMMING
Function Overloading.
Review: Two Programming Paradigms
INTRODUCTION TO OBJECT-ORIENTED PROGRAMMING (OOP) & CONCEPTS
PRINCIPALES OF OBJECT ORIENTED PROGRAMMING
Lecture 1 Introduction.
Object Oriented Analysis and Design
Lecture 22 Inheritance Richard Gesick.
WEL COME PRAVEEN M JIGAJINNI PGT (Computer Science)
Object-Oriented Programming
Classes and Objects.
Object-Oriented Programming
UNIT I OBJECT ORIENTED PROGRAMMING FUNDAMENTALS
CPS120: Introduction to Computer Science
Introduction to Data Structure
Object-Oriented Programming
Object-Oriented PHP (1)
CPS120: Introduction to Computer Science
Object-Oriented Programming
C++ Object Oriented 1.
Computer Science II for Majors
Presentation transcript:

OBJECT ORIENTED PROGRAMMING Welcome to OBJECT ORIENTED PROGRAMMING Prepared By : Nishant Tiwari PGT(CS) JNV,Padmi,Mandla

INTRODUCTION Structured programming was most common way to organize a program. A programming paradigm defines the methodology of designing and implementing program using the key features and building blocks of a programming language

PROCEDURAL PROGRAMMING Lays more emphasis on procedure than data Separates the function and data manipulated by them Whenever the definition of a type changes, the functions referring to this type must also be changed to reflect the change

PROCEDURAL PROGRAMMING The change in the design must also be modified to copy with the change in structure that shows procedural programming is susceptible to design changes As design changes lead to many modification in the code this lead to increased time and cost overheads at times

OBJECT BASED PROGRAMMING In object based programming data and its associated meaningful function are enclosed in one single entity a class Class are allowed to access its interface (how the uses views) but cannot access its implementation details (how the process is actually taking place)

OBJECT BASED PROGRAMMING Whenever any change in the definition of type user’s interface remains unaffected generally The user cannot access the data of the class directly which is possible in procedural programming the change is localized to the definition of the change function

OBJECT BASED PROGRAMMING Subset of object oriented programming Implement some feature of OOP like information hiding, abstraction, classes, function overloading but not implement inheritance and polymorphism

OBJECT BASED PROGRAMMING Advantages : overcome most shortcoming of procedural programming it localizes the changes and hide implementation details from user It support user defined types Implement information hiding and abstraction

OBJECT BASED PROGRAMMING Limitation One major limitation is ability to represent real world relationships that exist among object for example both car and truck are vehicles this cannot be represented in OBP as it not support inheritance

OBJECT ORIENTED PROGRAMMING Superset of OBP All the features of OBP and overcome its limitation by implementing inheritance so that real world relation among object can be represented programmatically

OBJECT ORIENTED PROGRAMMING OOP Concepts are data abstraction, data hiding, data encapsulation, classes, objects, inheritance and polymorphism. Implementing OOP Concepts in C++ Approach for writing software in which data and behavior are packed together An abstraction is a named collection of attributes and behavior relevant to modeling a given entity

OBJECT ORIENTED PROGRAMMING A class is a named software representation for an abstraction An object is a distinct instance of a class Software code in OOPs is written to define classes, objects and manipulate these object

Implementing objects Real World objects have physical characteristics (state) and behavior e.g., motorbike Characteristics – current gear, two wheel etc Behavior – braking, accelerating etc Their state is maintained through variables or data items Their behaviour is implemented through function generally called methods

Mapping an Abstraction into software Real world Abstraction software {data,data…} {method,method} attributes entity behaviour

Implementing Data hiding, Data Abstraction and Encapsulation Encapsulation is wrapping up of characteristics and behaviour into one unit A class bind together data and its associated functions under one unit thereby enforcing encapsulation Abstraction means representation of essential features without including the background details or explanation

Implementing Encapsulation Anything that an object does not know or cannot do is excluded from the object Encapsulation is used to hide unimportant implementation details from the objects Packing an object’s variables within the protective custody of its methods is encapsulation and this task is accomplished through classes

General structure of a class {data,data,….} {method,method,…} Private Protected Public

A Class is define as Class <class name> { private: // hidden members/methods protected: //unimportant implementation details public : // exposed important details };

Implementing Inheritance Inheritance is implement in C++ specifying the name of the (base) class from which the class being defined (the derived class) has to inherit from it. Class <derived class name>:<base class name> { derived class own features }

Abstract class and Concrete class Which defines an interface but does not provide implementation for all its member function 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 implementations 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 drives from abstract class

Abstract class and Concrete class Example Concrete class Circle class Abstract class Shape Concrete class Recantagle class Concrete class Triangle class

Implementing polymorphism Polymorphism is the attribute that allows one interface to be used with different situation C++ implement polymorphism through virtual functions, overloaded functions and overloaded operators. A virtual function is used to specify the interface in abstract class but its implementation details are made available in concrete class (es) Overloading means a name having two or more distinct meaning

Function Overloading A function with same name having several definitions that are differentiable by the number or types of their arguments is known as overloaded function and this process is known as function overloading Example float sum (int a, int b); float sum (float x,float y);

Function Overloading Function overloading not only implement polymorphism but also reduce number of comparison in a program Pop(int) Push(int) Push(float) Pop(float)

Declaration and Definition A function argument list is known as function’s signature Example void squar (int a, float b); //function 1 Void squar (int x, float y);// same signature as function 1

Declaration and Definition Different signatures void prnsqr ( int i); void prnsqr ( char c); void prnsqr ( float f); void prnsqr ( double d);

Declaration and Definition When a function name is declare more than once in a program the compiler will interpret the second (and subsequent) declaration (s) as follows : 1) If the signatures of subsequent functions match the previous function’s then the second is treated as a re-declaration of the first 2) If the signature of the two functions match exactly but the return type differ,the second declaration is treated as an erroneous re-declaration of the first and is flagged at compile ttime as an error for example; flaot square (float f); double square (float x); // error

Declaration and Definition Function with same name and same signature but different return type are not allowed in C++ You can have different return types, but only if the signature are also different: float square (float f);// different signature double square (double d); // allowed If the signature of the function differ in either the number or type of their arguments, the two function are considered to be overloaded

Questions OOP Q1 write briefly about different programming paradigms ? Q2 Discuss major OOP concepts briefly? Q3 what is the signifance of private, protected public specifiers in a class? Q4 Discuss the relation between abstract and concrete classes ? Q5 How polymorphism implemented in c++ ? Q6 How does the complier interpret more than one definitions having same name ? What steps does it follow to distinguish these ?

Questions OOP Q7 what will be the output of following program? #include<iostream.h> Int area (int s) { Return (s*s); } Float area (int b,int h) Return (o.5 * b* h); Int main ( ) Cout <<area(5)<<endl; Cout<<area(4,3)<<endl; Cout<<area(6,area(3))<<endl; Return 0;

0rganization of data and functions in OOP object object data data function function data function

Structural of procedural programming Main function Function Function Function Function function Function Function Function

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

Restrictions on Overloaded Functions Example typedef char * PSTR void Print(char *szToPrint); void Print(PSTR szToPrint); The preceding two function have identical lists. PSTR is synonym for char*.

Calling overloaded functions A function call first matches the prototypes available with number and type of arguments provided with the function call and then call the appropriate function for execution

Step involved in Finding the best match A match: A match is found for the function call No match: No match is found for a function call Ambiguous match: More than one defined match for the function call

Step involved in Finding the best match Search for exact match :if the type of the actual argument exactly matches the type of one defined instance A match through promotion : if no exact match is found an attempt is made to achieve a match through of the actual argument A match through application of standard C++ conversion rules : if no match or through a promotion is found an attempt is made to achieve a match through a standard conversion of the actual argument

Step involved in Finding the best match A match through application of a user-defined conversion: if all the above mentioned step fail, then the compiler will try the user-defined conversions in combination with integral promotions and built-in conversion to find a unique match

Advantages of OOP Re-use of code : linking of code to objects and explicit specification of relations between objects allows related objects to share code Ease of comprehension: the classes can be set up to closely represent the generic application concepts and process Ease of fabrication and maintenance : the concepts such as encapsulation, data abstraction allow for very clear designs when an object is going into disallowed states, which are not permitted only its methods needs to investigated Easy redesign and extension : the same concepts facilitate easy redesign and extension

Thank You !!!