0% found this document useful (0 votes)
2 views23 pages

Oops Concepts

The document provides an overview of Object-Oriented Programming (OOP) and its key concepts, including classes, objects, encapsulation, inheritance, polymorphism, and data abstraction. It contrasts OOP with procedure-oriented programming, highlighting the advantages of OOP such as improved software quality, reduced maintenance costs, and code reusability. Additionally, it lists various object-oriented programming languages and applications in fields like user interface design, real-time systems, and artificial intelligence.

Uploaded by

vishwaranjan41
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views23 pages

Oops Concepts

The document provides an overview of Object-Oriented Programming (OOP) and its key concepts, including classes, objects, encapsulation, inheritance, polymorphism, and data abstraction. It contrasts OOP with procedure-oriented programming, highlighting the advantages of OOP such as improved software quality, reduced maintenance costs, and code reusability. Additionally, it lists various object-oriented programming languages and applications in fields like user interface design, real-time systems, and artificial intelligence.

Uploaded by

vishwaranjan41
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 23

OBJECT ORIENTED

PROGRAMMING
INTRODUCTION TO OBJECT ORIENTED PROGRAMMING
AND C++

• many programming approaches have been tried. These


included techniques such as
 modular programming,
 top-down programming,
 bottom-up programming and
 structured programming.
• The primary motivation
reliable and maintainable
PROCEDURE-ORIENTED
PROGRAMMING
• Conventional programming using high level languages
such as COBOL, FORTRON, and C is commonly known as
procedure- oriented programming.
• The problem is viewed as a sequence of things to be done,
such as reading, calculating and printing.
• The primary focus is on functions.

• Disadvantage :
Very little attention is given to the data that are being
used by various functions.
BASIC CONCEPTS OF OBJECT-ORIENTED
PROGRAMMING

• The Focus is on the objects that compose the problem


domain, their behavior and communication between
the objects.

• General concepts Used extensively in object-oriented


programming are:
▫ Objects
▫ Classes
▫ Data encapsulation
▫ Data abstraction
▫ Inheritance
▫ Polymorphism
▫ Dynamic binding
▫ Message Passing
What is an Object?
• Objects have states and behaviors.
Example: A dog has states - color, name, breed as
well as behaviors -wagging, barking, eating.
• An object is an instance of a class.
• An object can be considered a "thing" that can perform a
set of related activities.

• Class - A class can be defined as a template/blue print


that describes the behaviors/states that object of its type
support.
public class Dog{
String breed;
int age;
String color;
void barking(){ }
void hungry(){ }
void sleeping(){ }
}

Object creation
Dog Boxer=new Dog();
Data Encapsulation
• C++ provides the facility to encapsulate data and the relevant
functions together in the same object.
Example:
• Customer uses the swipe interface provided by the machine to swipe
the card.
• The swipe Machine encapsulates/hides the internal circulatory from
all the users and provides simple interface for access by every user.

A Mechanism of hiding the internal details and allowing a simple


interface which ensures that the object can be used without having to
know how it works.

Data Hiding
Related to the idea of encapsulation is the concept of data hiding.
Encapsulation hides the data from other classes and functions in other
classes.
• by the use of keywords private, protected, and public
class Box {
public:
double getVolume(void) {
return length * breadth * height;
}
private:
double length; // Length of a box
double breadth; // Breadth of a box
double height; // Height of a box
};
• Abstraction:
Data abstraction refers to, providing only essential
information to the outside world and hiding their
background details, i.e., to represent the needed information
in program without presenting the details.
Example:
Customers need to know only what to purchase and
the mode of payment.
• Inheritance:
One of the most useful aspects of object-oriented
programming is code reusability. As the name suggests
Inheritance is the process of forming a new class from an
existing class that is from the existing class called as base
class, new class is formed called as derived class.
• Polymorphism:
The ability to use an operator or function in different
ways in other words giving different meaning or functions to
the operators or functions is called polymorphism.
• Poly refers to many. That is a single function or an
operator functioning in many ways different upon the
usage is called polymorphism.
Overloading:
• The concept of overloading is also a branch of
polymorphism. When the exiting operator or function is
made to operate on new data type, it is said to be
overloaded.
• Example:Payment mode: cash or credit card.
#include <iostream>
using namespace std;
class Shape {
protected: int width, height;
public: Shape( int a=0, int b=0) {
width = a; height = b;
}
int area() {
cout << "Parent class area :" <<endl; return 0;
}
};

class Rectangle: public Shape{


public: Rectangle( int a=0, int b=0):Shape(a, b) { }
int area () {
cout << "Rectangle class area :" <<endl;
return (width * height);
}
};

class Triangle: public Shape{


public: Triangle( int a=0, int b=0):Shape(a, b) { }
int area () {
cout << "Triangle class area :" <<endl;
return (width * height / 2);
}
};
• Dynamic Binding refers to linking a procedure
call to the code that will be executed only at run time. The
code associated with the procedure in not known until the
program is executed, which is also known as late binding.
Example:
complier comes to know at runtime that which function of
sum will be call either with two arguments or with three
arguments
• It is generally use with polymorphism and inheritance.
• Message Passing:
Objects can communicate with each others by passing
message same as people passing message with each other.
• Objects can send or receive message or information.
• Message passing involves name of object, name of function
(message) and information to be send.
• For example, student.mark(name). Here student is object,
mark is message, name is information.
OOPs Summary
BENEFITS OF OOP

• Quality of software products.


• Lesser maintenance cost
• Eliminate redundant code
• Extend the use of existing classes
• Build programs from the standard working
modules
• Build secure programs
• Multiple instances of an object to co-exist
without any interference.
• Interface with external systems
• Software complexity can be easily managed
Object Oriented Languages
• C++
• Java
• MATLAB
• Perl
• Python
• Ruby
• Visual Basic (.NET)
Applications of using OOP:
Main application areas of OOP are
• 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 system etc
Class

A class is a blueprint for creating objects. It defines properties (variables) and


behaviors (functions) that an object can have.
class Car {
public:
string brand;
int year;

void start() {
cout << "Car started" << endl;
}
};
Object
An object is an instance of a class. It is used to access the members
(variables/functions) of the class.
int main() {
Car myCar; // Create object
myCar.brand = "Toyota";
myCar.year = 2022;

cout << myCar.brand << " " << myCar.year << endl;
myCar.start(); // Call method
return 0;
• }
Encapsulation
Encapsulation means hiding internal details and only exposing necessary parts
through public methods.
class Account {
private:
double balance;

public:
void setBalance(double b) {
if (b > 0)
balance = b;
}

double getBalance() {
return balance;
}
• };
Inheritance

Inheritance allows a class (child) to inherit properties and behaviors from another class (parent).
class Vehicle {
public:
void honk() {
cout << "Beep beep!" << endl;
}
};

class Car : public Vehicle {


public:
void drive() {
cout << "Driving..." << endl;
}
};
int main() {
Car myCar;
myCar.honk(); // Inherited from Vehicle
• myCar.drive();
Polymorphism

Polymorphism means many forms—you can use the same function name but different
behaviors depending on the object
Compile-time (Function Overloading)
class Print {
public:
void show(int i) {
cout << "Integer: " << i << endl;
}
void show(string s) {
cout << "String: " << s << endl;
}
• };
Concept Description
Class Blueprint for objects
Object Instance of a class
Encapsulation Hiding data using access modifiers
Abstraction Hiding complexity, showing only features
Inheritance Acquiring properties from another class
Polymorphism One interface, multiple behaviors

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy