OOP-1st Lecture - Building Block
OOP-1st Lecture - Building Block
Concepts
What is OOP ?
Object Oriented Programming is programming
technique through which we can implement
ideas, concepts, functionality like they are
presented in real life.
Elements of OOP
Definition of OOP:
Object oriented programming is a
programming methodology that associates
data structures with a set of operators which
act upon it.
Elements of OOP
Classes
Objects
Encapsulation
Data Abstraction
Inheritance
Polymorphism
Dynamic Binding
Message Passing
Overloading
Class
Class is a collection of similar objects.
Class
Classes
Operation
Operation
Example: StudentObject
Enroll()
st_name
st_id
Performa Displayinfo()
branch
nce()
semester
Result()
Encapsulation
Mechanism that associates the code and the
data it manipulates into a single unit and
keeps them safe from external interference
and misuse.
Encapsulation
Class: student
Functions: Enroll()
Displayinfo()
Result()
Performance()
Data Abstraction
A data abstraction is a simplified view of an
object that includes only features one is
interested in while hides away the
unnecessary details.
Point
Line
Inheritance
Fruit
Polygon
Triangle Rectangle
Polygon Inheritance
Triangle RightAngle
Triangle
Base Class
Base class is a class which defines those
qualities common to all objects to be derived
from the base.
+
Dynamic Binding
Dynamic Binding is the process of linking of
the code associated with a procedure call at
the run-time.
Message Passing
The process of invoking an operation on an
object. In response to a message the
corresponding method is executed in the
object.
Message Passing
StudentObject FacultyObject
Performance
MgmtObject Performance
Result
Simple C++ Program
// Hello World program comment
int main() {
Starts definition of special function
main()
cout << "Hello World\n";
output (print) a
string
return 0;
Program returns a status
} code (0 means OK)
Preprocessing
Temporary file
C++ (C++ program) C++
Preprocessor Compiler
Executable
C++ Program Program
Class Specification
Syntax:
class class_name
{
Data members
Members functions
};
Class Specification
class Student
{
int st_id; Data Members or Properties of
Student Class
char st_name[];
void read_data(); Members Functions or
Behaviours of Student Class
void print_data();
};
Class Objects
Object Instantiation:
The process of creating object of the type class
Syntax:
class_name obj_name;
ex: Student st;
St_id, St_name
void read_data( )
void print_data( )
Class Object
More of Objects
ex: Student st1;
Student st2;
Student st3;
Class Objects
st1 st2
55, Mary
void read_data( )
void print_data( )
st3
Defining Member Functions
Syntax :(Inside the class definition)
ret_type fun_name(formal parameters)
{
function body
}
Defining Member Functions
Syntax:(Outside the class definition)
ret_type class_name::fun_name(formal parameters)
{
function body
}
Data Hiding
Data hiding is the mechanism of
implementation details of a class such a way
that are hidden from the user.
private:
st_name
Cal_best() st_id Print_data()
branch
semester
Result()
Data Hiding
The access specifier acts as the key strength
behind the concept of security.