Unit-I Object Oriented Concepts PDF

Summary

This document discusses object-oriented programming concepts. It covers fundamental topics like encapsulation, inheritance, polymorphism, and abstraction. The material is presented in a slide format and focuses on providing a high-level overview of these key OOP concepts, particularly relevant to C++ programming.

Full Transcript

Course Code : 23CsBCAU401 Course Name : Programming in C++ Teaching Scheme: 2 Lectures/Week Credits: 2 Examination Scheme: CIA : 20 Marks End-Sem : 30 Marks Unit 1 Object oriented concepts Object-oriented programming aims to im...

Course Code : 23CsBCAU401 Course Name : Programming in C++ Teaching Scheme: 2 Lectures/Week Credits: 2 Examination Scheme: CIA : 20 Marks End-Sem : 30 Marks Unit 1 Object oriented concepts Object-oriented programming aims to implement real-world entities like inheritance, hiding, polymorphism, etc in programming. 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. 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. For Example: Consider the Class of Cars. There may be many cars with different names and brand but all of them will share some common properties like all of them will have 4 wheels, Speed Limit, Mileage range etc. So here, Car is the class and wheels, speed limits, mileage are their properties. 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 behaviour of the objects in a Class. In the above example of class Car, the data member will be speed limit, mileage etc and member functions can apply brakes, increase speed etc. Object An Object is an identifiable entity with some characteristics and behaviour. 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. Polymorphism Polymorphism is the ability of an object to perform different actions (or, exhibit different behaviors) based on the context. 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. A person at the same time can have different characteristic. Like a man at the same time is a father, a husband, an employee. So the same person posses different behaviour in different situations. This is called polymorphism. 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. Inheritance Inheritance can be defined as the process where one (parent/super) class acquires the properties (methods and fields) of another (child/sub). With the use of inheritance, the information is made manageable in a hierarchical order. Polymorphism is extensively used in implementing 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. Encapsulation Encapsulation is a mechanism for wrapping the data (variables) and code acting on the data (methods) together as a single unit. In encapsulation, the variables of a class will be hidden from other classes and can be accessed only through the methods of their current class. Therefore, it is also known as data hiding. To achieve encapsulation − 1. Declare the variables of a class as private. 2. Provide public setter and getter methods to modify and view the variables values. In normal terms, 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. As using encapsulation also hides the data. Abstraction Abstraction is a process of hiding the implementation details from the user, only the functionality will be provided to the user. In other words, the user will have the information on what the object does instead of how it does it. In Java, abstraction is achieved using Abstract classes and interfaces. Advantages of OOP 1. Simplicity: software objects model real world objects, so the complexity is reduced and the program structure is very clear; 2. Modularity: each object forms a separate entity whose internal workings are decoupled from other parts of the system; 3. Modifiability: it is easy to make minor changes in the data representation or the procedures in an OO program. Changes inside a class do not affect any other part of a program, since the only public interface that the external world has to a class is through the use of methods; 4. Extensibility: adding new features or responding to changing operating environments can be solved by introducing a few new objects and modifying some existing ones; 5. Maintainability: objects can be maintained separately, making locating and fixing problems easier; 6. Re-usability: objects can be reused in different programs Main application areas of OOPs User interface design such as windows, menu. Real Time Systems. Simulation and Modeling. Object oriented databases. AI and Expert System. Neural Networks and parallel programming. Decision support and office automation systems etc.

Use Quizgecko on...
Browser
Browser