Object Oriented Programming-It20301: Dr. Madasamy Raja, B.E, M.E., PH.D., Associate Professor
Object Oriented Programming-It20301: Dr. Madasamy Raja, B.E, M.E., PH.D., Associate Professor
• ALGOL-1958
• BASIC-1964
• C-1972
• C++-1980
• OBJECT ORIENTED CONCEPTS-1962
• Examples of object-oriented programming
languages are C++, Java, Smalltalk, Delphi, C#,
Perl, Python, Ruby, and PHP.
NEED OF OBJECT ORIENTED PARADIGM
Following are the disadvantages of procedural or structured
languages:
• TV- Class
– Attributes: panel, remote type, smart support, etc.
– Methods: net connecting, USB connection,
changing the volume, etc.,
CLASS-OBJECT EXAMPLE(Contd….)
• Programming point of view…
• Class- Circle
– Attributes: xcoord, ycoord, radius
– Methods: area(), circumference(), scale()
• Class: Student
- Data: name , DOB, Marks
- Functions: Average(), Age(), Grade()
Recap…
• Encapsulation
• Abstraction
• Inheritance
• Polymorphism
ENCAPSULATION
• Encapsulation is the process of binding both
attributes and methods together within a
class. Through encapsulation, the internal
details of a class can be hidden from outside.
• Data within a class cannot be accessed from
outside and only the methods within the class
can access those data. This is called as ‘Data
Hiding’ or ‘Information Hiding’
ABSTRACTION
• Act of including the needed information and
eliminating the irrelevant details
• Achieved through the concept encapsulation
• Classes are otherwise called as Abstract Data
Type(ADT)
INHERITANCE
• New classes can be created from existing classes by
extending and refining its properties
• The existing classes are called the base classes/parent
classes/super-classes, and the new classes are called the
derived classes/child classes/subclasses.
• The subclass can inherit or derive the attributes and
methods of the super-class(es).
• Besides, the subclass may add its own attributes and
methods and may modify any of the super-class
methods.
INHERITANCE-EXAMPLE
TYPES OF INHERITANCE
• Single Inheritance − A subclass derives from a single super-
class.
• Multiple Inheritance − A subclass derives from more than
one super-classes.
• Multilevel Inheritance − A subclass derives from a super-class
which in turn is derived from another class and so on.
• Hierarchical Inheritance − A class has a number of subclasses
each of which may have subsequent subclasses, continuing
for a number of levels, so as to form a tree structure.
• Hybrid Inheritance − A combination of multiple and
multilevel inheritance so as to form a lattice structure.
TYPES OF INHERITANCE(Contd…)
POLYMORPHISM
• Ability of variable, function or object to take
on different forms.
• Single method with different behaviours in the
same class or different classes is known as
polymorphism.
• Behaviour depends upon the types of data
used in the method.
• Different operation in different instances
• Fine, bat, etc.,- Homograph
• Man- father, husband, friend, employee, etc.,
POLYMORPHISM
ADDITIONAL OOPS CONCEPTS-DYNAMIC
BINDING
• A block of code executed with reference to a
procedure(method) call is determined at run
time
• Otherwise called as Runtime Binding or Late
Binding
ADDITIONAL OOPS CONCEPTS-MESSAGE
PASSING
• Objects communicate with one another by
sending and receiving information to each
other. This is called Message Passing
• A message for an object is a request for
execution of a procedure and therefore will
invoke a function in the receiving object
• Message passing involves specifying the name
of the object, the name of the function and
the information to be sent.
ADDITIONAL OOPS CONCEPTS-MESSAGE
PASSING(Contd…)
MERITS OF OOPS
• Data Security-Data hiding
• Redundancy is reduced-Inheritance
• Data Centered approach- easily complete details of objects
can be implemented
• Can be easily implemented for the real life projects
• Easily partitioned into many modules based upon the Classes
• Communication between the modules cane be easily done-
Message Passing
• Scaling can be done easily
• Polymorphism saves much time and reduce the length of
coding
DEMERITS OF OOPS
• Unfamiliarity concepts needs more vigorous
training
• Data protection is needed since data centered
approach
• Inability to work with the existing systems
• Compile time and Runtime overhead
C++ FUNDAMENTALS
C++ FUNDAMENTALS-Contd..
// Simple C++ program to display "Hello World“-
Comments Section
ignored by C++
compiler
• #include<iostream>
using namespace std; - Header Section (Header file
for i/o
functions )
• int main() - main function
• {
• cout<<"Hello World"; - body of the main program
• }
C++ FUNDAMENTALS-Contd..
Variables
Assignments
Data Types
Operators
Expressions
Simple Flow of Control
VARIABLES
• Variables are like small blackboards
– We can write a number on them
– We can change the number
– We can erase the number
• C++ variables are names for memory locations
– We can write a value in them
– We can change the value stored there
– We cannot erase the memory location
• Some value is always there
VARIABLES (Contd…)
• Variables names are called identifiers
• Choosing variable names
– Use meaningful names that represent data to
be stored
– First character must be
• a letter
• the underscore character
– Remaining characters must be
• letters
• numbers
• underscore character
VARIABLES (Contd…)
• Keywords (also called reserved words)
– Are used by the C++ language
– Must be used as they are defined in
the programming language
– Cannot be used as identifiers
VARIABLES (Contd…)
• Before use, variables must be declared
• Declaration Examples:
– double average, m_score, total_score;
– double moon_distance;
– int age, num_students;
– int cars_waiting;
ASSIGNMENTS
• An assignment statement changes the value of a variable
– total_weight = one_weight + number_of_bars;
• total_weight is set to the sum one_weight + number_of_bars
number_of_bars = number_of_bars + 3;