Principles of OOPs.pptx

LakshyaChauhan21 81 views 12 slides Jul 18, 2022
Slide 1
Slide 1 of 12
Slide 1
1
Slide 2
2
Slide 3
3
Slide 4
4
Slide 5
5
Slide 6
6
Slide 7
7
Slide 8
8
Slide 9
9
Slide 10
10
Slide 11
11
Slide 12
12

About This Presentation

To learn about the basic principles of C++ object oriented programing....


Slide Content

Introduction to O bject-Oriented P rogramming Object-oriented programming aims to implement real-world entities. The main aim of OOP is to bind together the data and the functions that operate on them so that no other part of the code can access this data except that function . Object oriented programming can be defined as a programming model which is based upon the concept of objects. Objects contain data in the form of attributes and code in the form of methods. In object oriented programming, computer programs are designed using the concept of objects that represent real world object. Some of the Object Oriented Programming Languages : Java, C++, C#, Python, PHP, JavaScript, Ruby, Perl, Objective-C, Dart, Swift, Scala. 1

Characteristics of OOP 2

CLASS The building block of C++ that leads to Object-Oriented programming is a Class. It is a user-defined data type, which holds its own data members and member functions, which can be accessed and used by creating an instance of that class. A class is like a blueprint for an object. A Class is a user-defined data-type which has data members and member functions. Data members are the data variables and member functions are the functions used to manipulate these variables and together these data members and member functions define the properties and behavior of the objects in a Class. In the example of class Car, the data member will be speed limit, mileage etc and member functions can apply brakes, increase speed etc. 3

OBJECT An Object is an identifiable entity with some characteristics and behavior. An Object is an instance of a Class. When a class is defined, no memory is allocated but when it is instantiated (i.e. an object is created) memory is allocated. Object take up space in memory and have an associated address like a record in pascal or structure or union in C. When a program is executed the objects interact by sending messages to one another. Message Passing: Objects communicate with one another by sending and receiving information to each other. A message for an object is a request for execution of a procedure and therefore will invoke a function in the receiving object that generates the desired results. Message passing involves specifying the name of the object, the name of the function and the information to be sent. 4

Class Vs Object 5

Encapsulation Abstraction Inheritance 6

Encapsulation is defined as wrapping up of data and information under a single unit. In Object-Oriented Programming, Encapsulation is defined as binding together the data and the functions that manipulate them. Encapsulation also leads to data abstraction or hiding . Abstraction means displaying only essential information and hiding the details. Data abstraction refers to providing only essential information about the data to the outside world, hiding the background details or implementation. 7

Inheritance: The capability of a class to derive properties and characteristics from another class is called Inheritance. Inheritance is one of the most important features of Object-Oriented Programming. Sub Class : The class that inherits properties from another class is called Sub class or Derived Class. Super Class : The class whose properties are inherited by sub class is called Base Class or Super class. Reusability : Inheritance supports the concept of “reusability”, i.e. when we want to create a new class and there is already a class that includes some of the code that we want, we can derive our new class from the existing class. By doing this, we are reusing the fields and methods of the existing class. 8

Polymorphism: The word polymorphism means having many forms. In simple words, we can define polymorphism as the ability of a message to be displayed in more than one form. An operation may exhibit different behaviours in different instances. The behaviour depends upon the types of data used in the operation. C++ supports operator overloading and function overloading. Operator Overloading : The process of making an operator to exhibit different behaviours in different instances is known as operator overloading. Function Overloading : Function overloading is using a single function name to perform different types of tasks. Polymorphism is extensively used in implementing inheritance. 9

Advantages of OOP A real-world idea can be demonstrated, as everything in OOP is treated as an object. As we use the concept of encapsulation, programs are easier to test and maintain. Faster development of code is done as we develop classes parallel instead of sequentially. OOP provides greater security due to data abstraction. The outside world cannot access the hidden data. Reusability can be achieved through inheritance by using classes that have been already written. Flexibility through polymorphism. 10

Advantages of OOP contd.. OOP systems can be easily upgraded from small to large systems. It is possible that multiple instances of objects co-exist without any interference, It is very easy to partition the work in a project based on objects. OOP language allows to break the program into the bit-sized problems that can be solved easily (one object at a time). 11

Comparison POP vs OOP Procedural Oriented Programming Object Oriented Programming Structure oriented Object oriented Program is divided into functions . Program is divided objects . Procedural programming follows top down approach . Object oriented programming follows bottom up approach . No access specifier in procedural programming. Have access specifiers like private, public, protected etc. Adding new data and function is not easy. Adding new data and function is easy. No data hiding. Encapsulation is used to hide the data. Does not have provision for hiding data so it is less secure . Provides data hiding so it is more secure . No virtual function. Concept of virtual function. Overloading is not possible. Overloading is possible Function is more important than data. Data is more important than function. Examples: C, FORTRAN, Pascal, Basic etc. Examples : C++, Java, Python, C# etc . 12