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

Object Oriented Programming C++

This document provides an introduction to object oriented programming concepts like classes, objects, methods, and constructors. It discusses the difference between a class and an object, with a class being a user-defined data type that defines properties and behaviors and an object being an instance of a class. The document also covers object types, class characteristics like identity and state, and benefits of OOP like reusability, code maintenance, and security. Constructors are described as special methods that initialize an object's data members. Various presenters are also listed to discuss different OOP topics.

Uploaded by

Techknow Asia
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
Download as pptx, pdf, or txt
0% found this document useful (0 votes)
56 views23 pages

Object Oriented Programming C++

This document provides an introduction to object oriented programming concepts like classes, objects, methods, and constructors. It discusses the difference between a class and an object, with a class being a user-defined data type that defines properties and behaviors and an object being an instance of a class. The document also covers object types, class characteristics like identity and state, and benefits of OOP like reusability, code maintenance, and security. Constructors are described as special methods that initialize an object's data members. Various presenters are also listed to discuss different OOP topics.

Uploaded by

Techknow Asia
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
Download as pptx, pdf, or txt
Download as pptx, pdf, or txt
You are on page 1/ 23

Introduction to Object Oriented Programming

Classes,Objects and its type, methods and constructor


What we will cover

• Difference between class and object

• Types of Objects
• Characteristics of Objects

• Constructor
• Benefits of OOP
• Methods
Presenters

• Hamd Al Saleh

• Saad Bin Waqas


• Abdul Wassey

• Shazib Abdullah
• Syed Muhammad Ali
What is class ?

Class is a user defined datatype which holds its own data member and member
function. In other words we can say class is collection of data member and
member function , which can accessed and use by creating object of that class.

• 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 defines the properties and behavior 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 be apply brakes, increase
speed etc.
What is object ?

An object is an instance of a class, when ever the class is


defined , no memory is allocated but when the object is
initialized , memory is allocated of that class.

How many access specifier in?


There are 3 access specifier :
1) Private
2) Public
3) Protected

Declaration of Class:

Syntax
Program:

Program in which class is declared by single object:


Program:

Program in which class is declared by 2 object:


Difference between Class and
objects
Class Object

Class is the blueprint of an


object. It is used to declare and Object is an instance of class.
create objects.

No memory is allocated when a Memory is allocated as soon as


class is declared. an object is created.

A class is a group of similar Object is a real-world


objects. entity such as book, car, etc.

Class is a logical entity. Object is a physical entity.

Class can only be Object can be created many


declared once. times as per requirement.

Objects of the class car can be


Example of class can be car.
BMW, Mercedes, jaguar, etc.
Saad Bin Waqas
Types of Objects in OOP

The term “Object-Oriented Programming ” (OOP) was coined by Alan Kay around 1966. The
language Simula was the first programming language with the features of Object oriented
programming.

Defining Objects

The first statement in main() smallobj s1, s2 defines two objects.


Types of Objects

• Function objects contain a single function and are used similarly to operating system or
programming language functions.
• Immutable objects are not changed after their creation. Data and state of the object are fixed
and are not changed by use of function.
• Container objects may contain other objects.
• Factory objects are designed to create other objects.

Function Objects in C++ Standard Library

A function object or functor, is any type that implements operator(). This operator is
referred to as the call operator or sometimes the application operator.
Creating a Function Object
To create a function object, create a type and implement operator(), such as

The last line of the main function shows how you can call the function object. It’s calling
operator() of the Functor type.
Abdul Wassey
Characteristics of Objects

• Identity means that each object has its own object indentifier and can be differentiated from
all other objects.
• State refers to the properties of an object. For example values of variables in the object
contain data that can be added, changed or deleted.
• Behaviour refers to actions that the object can take. For example, one object can respond to
another object to carry out software functions.

Some things in programming that can be defined as objects


• Variables which hold values that can be changed.
• Data Structures which are specialized formats used to organize and process data.
• Functions which are named procedures that perform a defined task.
• Methods which are programmed procedures that are defined as components of a parent
class and are included in any instance of that class.
Constructors in C++

• Constructor in C++ is a special method that is invoked automatically at the time of object
creation.
Same name as Class

• There are some unusual aspects of constructor functions. First, it is no accident that they
have exactly the same name as the class of which they are members. This is one way the
compiler knows they are constructors.

Initializer List

• One of the most common tasks a constructor carries out is initializing data members.
Shazib Abdullah
Benefits of OOP

• Re-usability It means reusing some facilities rather than building them again and again. This
is done with the use of a class. We can use it ‘n’ number of times as per our need.
• Data Redundancy This is a condition created at the place of data storage (Databases) where
the same piece of data is held in two seperate places. So the data redundancy is one of the
greatest advantages of OOP.
• Code Maintenance This feature is more of a necessary for any programming languages; it
helps users from re-work in many ways.
• Security With the use of data hiding and abstraction mechanism, we are filtering out limited
data to exposure, which means we are maintaining security and providing necessary data to
view.
• Design Benefits If you are practicing on OOPs, the design benefit a user will get is in terms
of designing and fixing things easily and eliminating the risks.
• Better Productivity With the above mentioned facts of using the application definitely
enhances its users overall productivity.
Syed Muhammad Ali
C++ Class Methods

Methods are functions that belong to the class


There are two ways to define functions that belong to a class:
• Inside class definition
• Outside class definition
Outside Class Function Definition

You might also like