1. Class and Objects in C++
1. Class and Objects in C++
University
Computer Science Faculty
Object Oriented
Programming (C++)
C++ Classes & Objects
Outline
What is OOP?
OOP Concepts
Classes
Objects
Defining Classes
What is OOP?
OOP stands for Object-Oriented
Programming.
Procedural programming is about writing
procedures or functions that perform
operations on the data, while object-oriented
programming is about creating objects that
contain both data and functions.
Object-oriented programming has several
advantages over procedural programming:
What is OOP?
OOP is faster and easier to execute
OOP provides a clear structure for the programs
OOP helps to keep the C++ code DRY "Don't
Repeat Yourself", and makes the code easier to
maintain, modify and debug
OOP makes it possible to create full reusable
applications with less code and shorter
development time
What is OOP?
Tip: The "Don't Repeat Yourself" (DRY) principle
is about reducing the repetition of code.
You should extract out the codes that are common
for the application, and place them at a single
place and reuse them instead of repeating it.
What are Classes and
Objects?
Classes and objects are the two main aspects of
object-oriented programming.
Look at the following illustration to see the
difference between class and objects:
What are Classes and
Objects?
What are Classes and Objects?
Classes
The main purpose of C++ programming is
to add object orientation to the C
programming language
classes are the central feature of C++ that
supports object-oriented programming
A class is used to specify the form of an
object and
It combines data representation and
methods for manipulating.
Classes
The data and functions within a class are called
members of the class.
C++ Class Definitions
Class is blueprint for a data type
What an object of the class will consist of
What operations can be performed on such
an object
Object Properties
Attributes
Behaviors (Functionalities)
Define C++ Objects
A class provides the blueprints for objects,
so basically an object is created from a
class.
Example
Important
It is important to note that private and
protected members can not be accessed
directly using direct member access
operator (.)
We will learn how private and protected
members can be accessed
Class Activity
Make class of diagram below
Any Questions?