Presentation is loading. Please wait.

Presentation is loading. Please wait.

OBJECT ORIENTED PROGRAMMING

Similar presentations


Presentation on theme: "OBJECT ORIENTED PROGRAMMING"— Presentation transcript:

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

2 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

3 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

4 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

5 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)

6 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

7 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

8 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

9 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

10 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

11 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

12 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

13 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

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

15 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

16 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

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

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

19 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 }

20 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

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

22 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

23 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);

24 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)

25 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

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

27 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

28 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

29 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 ?

30 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;

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

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

33 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

34 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*.

35 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

36 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

37 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

38 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

39 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

40 Thank You !!!


Download ppt "OBJECT ORIENTED PROGRAMMING"

Similar presentations


Ads by Google