Object Oriented Programming C++
Object Oriented Programming C++
• Types of Objects
• Characteristics of Objects
• Constructor
• Benefits of OOP
• Methods
Presenters
• Hamd Al Saleh
• 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 ?
Declaration of Class:
Syntax
Program:
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
• 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.
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.
• 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