1
Object Oriented Programming
Development
By:
Anoop Gupta
SoftEra Informative
C-DAC Training
Email:
softera.informative@gmail.c
om
Oops ?
Object oriented programming is a
programming paradigm which uses
objects and its interactions to design
applications and computer programs.
Simula67 was the first object-oriented
programming language. Java, Python, C+
+, Visual Basic .NET and Ruby are the
most popular OOP languages today.
2
Oops Features ?
Class
Object
Encapsulation
Abstraction
Polymorphism
Inheritance
3
Class ?
Classes are user-defined (programmer-
defined) types.
Data (data members)
Functions (member functions or methods)
In other words, they are structures +
functions
Classes are logical entity which defines
behaviors and property for Object
4
Class
Examples -
•Animals
•Human
•Books
•Cricketer 5
Classes in C++
A class definition begins with the keyword
class.
The body of the class is contained within a
set of braces, { } ; (notice the semi-colon)
6
Class class_Name
{ ………
………
……..
};
Any valid identifier
Class body (data
member + methodsmethods)
Object ?
Object is a real time entity which exist
physically
Object occupy some space into memory
Every object have some specific property
and behavior but all objects from the
same class share common property and
behavior
7
Objects ?
•Animals
8
9
What are we doing today?
Introduction of:
the lecturer
Objects
Basic Terminology
C++
the module
Object
Fruits
10
Abstraction ?
Abstraction is another good feature of
OOPS. Abstraction means to show only
the necessary details to the client of the
object.
Abstraction says that hide un necessary
detail from the user which are not required
them
11
Abstraction
Abstraction
12
Encapsulation
Encapsulation is a process of binding or
wrapping the data and the codes that
operates on the data into a single entity.
This keeps the data safe from outside
interface and misuse.
Encapsulation Provide data security .
13
Encapsulation
Encapsulation defines the access levels
for elements of that class. These access
levels define the access rights to the data,
allowing us to access the data by a
method of that particular class itself, from
aninheritance class, or even from any
other class. There are three levels of
access:
14
Encapsulation
– Encapsulation
15
Polymorphism
16
17
What is Object Oriented
Programming?
An object is like a
black box.
The internal
details are
hidden.
Identifying objects and
assigning responsibilities to
these objects.
Objects communicate to
other objects by sending
messages.
Messages are received by
the methods of an object
18
What is an object?
Tangible Things as a car, printer, ...
Roles as employee, boss, ...
Incidents as flight, overflow, ...
Interactions as contract, sale, ...
Specifications as colour, shape, …
19
So, what are objects?
an object represents an individual,
identifiable item, unit, or entity, either real
or abstract, with a well-defined role in the
problem domain.
Or
An "object" is anything to which a concept
applies.
Etc.
20
Why do we care about
objects?
Modularity - large software projects
can be split up in smaller pieces.
Reuseability - Programs can be
assembled from pre-written software
components.
Extensibility - New software
components can be written or
developed from existing ones.
Example: The Person class
#include<string>
#include<iostream>
class Person{
char name[20];
int yearOfBirth;
public:
void displayDetails() {
cout << name << " born in "
<< yearOfBirth << endl;
}
//...
};
private
data
public
processes
22
The two parts of an object
Object = Data + Methods
or to say the same differently:
An object has the responsibility to know and
the responsibility to do.
= +
23
Basic Terminology
Abstraction is the representation of the
essential features of an object. These are
‘encapsulated’ into an abstract data type.
Encapsulation is the practice of including
in an object everything it needs hidden
from other objects. The internal state is
usually not accessible by other objects.
24
Basic Terminology:
Inheritance
Inheritance means that one class inherits
the characteristics of another class.
This is also called a “is a” relationship:
A car is a vehicle
A teacher is a person
A dog is an animal
25
Basic Terminology:
Polymorphism
Polymorphism means “having many
forms”. It allows different objects to
respond to the same message in different
ways, the response specific to the type of
the object.
E.g. the message displayDetails() of the
Person class should give different
results when send to a Student object
(e.g. the enrolment number).
26
Basic Terminology:
Aggregation
Aggregation describes a “has a”
relationship. One object is a part of
another object.
We distinguish between composite
aggregation (the composite “owns” the
part) and shared aggregation (the part is
shared by more then one composite).
A car has wheels.
27
Basic Terminology:
Behaviour and Messages
The most important aspect of an object is
its behaviour (the things it can do). A
behaviour is initiated by sending a
message to the object (usually by calling
a method).
28
The two steps of Object
Oriented Programming
Making Classes: Creating, extending or
reusing abstract data types.
Making Objects interact: Creating objects
from abstract data types and defining their
relationships.
29
Historical Notes
C++ owes most to C.
Other ancestors are Simula67
and Algol68.
First versions of C++ in 1980 under the
name “C with classes”. Since 1983 the
name C++ is used.
1990: ANSI/ISO 9899 defines a standard
for C
1998: ISO/IEC 14882 specifies the
standard for C++
C++ 1987
30
C++ and C
C is a subset of C++.
Advantages: Existing C libraries can be
used, efficient code can be generated.
But: C++ has the same caveats and
problems as C (e.g. pointer arithmetic,…).
C++ can be used both as a low level and
as a high level language.
We focus on the
high level aspects.
31
C++ and Java
Java is a full object oriented language, all
code has to go into classes.
C++ - in contrast - is a hybrid language,
capable both of functional and object
oriented programming.
So, C++ is more powerful but also
more difficult to handle than Java.
32
Module Outline
Introduction
The non object
oriented basics
Classes
Design Approaches
Testing
Inheritance
Aggregation
Polymorphism
Multifile Development
33
Assessment Details
50% in course and 50% exam.
For more details for the in course
assignment see separate handout.
34
Books
Teach Yourself C++ in 10 minutes,
J. Liberty, SAMS 1999.
C++ - How to program, Deitel & Deitel,
Prentice Hall, 2001.
Object Oriented Programming with C++,
David Parson, Letts Educational, London
1997.
35
Websites
A C++ online tutorial:
http://www.cplusplus.com/doc/tutorial/
The C++ FAQ:
http://www.parashift.com/c++-faq-lite
The homepage of Bjarne Stroustrup, the
inventor of C++:
http://www.research.att.com/~bs
And many, many more!

Week1

  • 1.
    1 Object Oriented Programming Development By: AnoopGupta SoftEra Informative C-DAC Training Email: softera.informative@gmail.c om
  • 2.
    Oops ? Object orientedprogramming is a programming paradigm which uses objects and its interactions to design applications and computer programs. Simula67 was the first object-oriented programming language. Java, Python, C+ +, Visual Basic .NET and Ruby are the most popular OOP languages today. 2
  • 3.
  • 4.
    Class ? Classes areuser-defined (programmer- defined) types. Data (data members) Functions (member functions or methods) In other words, they are structures + functions Classes are logical entity which defines behaviors and property for Object 4
  • 5.
  • 6.
    Classes in C++ Aclass definition begins with the keyword class. The body of the class is contained within a set of braces, { } ; (notice the semi-colon) 6 Class class_Name { ……… ……… …….. }; Any valid identifier Class body (data member + methodsmethods)
  • 7.
    Object ? Object isa real time entity which exist physically Object occupy some space into memory Every object have some specific property and behavior but all objects from the same class share common property and behavior 7
  • 8.
  • 9.
    9 What are wedoing today? Introduction of: the lecturer Objects Basic Terminology C++ the module
  • 10.
  • 11.
    Abstraction ? Abstraction isanother good feature of OOPS. Abstraction means to show only the necessary details to the client of the object. Abstraction says that hide un necessary detail from the user which are not required them 11
  • 12.
  • 13.
    Encapsulation Encapsulation is aprocess of binding or wrapping the data and the codes that operates on the data into a single entity. This keeps the data safe from outside interface and misuse. Encapsulation Provide data security . 13
  • 14.
    Encapsulation Encapsulation defines theaccess levels for elements of that class. These access levels define the access rights to the data, allowing us to access the data by a method of that particular class itself, from aninheritance class, or even from any other class. There are three levels of access: 14
  • 15.
  • 16.
  • 17.
    17 What is ObjectOriented Programming? An object is like a black box. The internal details are hidden. Identifying objects and assigning responsibilities to these objects. Objects communicate to other objects by sending messages. Messages are received by the methods of an object
  • 18.
    18 What is anobject? Tangible Things as a car, printer, ... Roles as employee, boss, ... Incidents as flight, overflow, ... Interactions as contract, sale, ... Specifications as colour, shape, …
  • 19.
    19 So, what areobjects? an object represents an individual, identifiable item, unit, or entity, either real or abstract, with a well-defined role in the problem domain. Or An "object" is anything to which a concept applies. Etc.
  • 20.
    20 Why do wecare about objects? Modularity - large software projects can be split up in smaller pieces. Reuseability - Programs can be assembled from pre-written software components. Extensibility - New software components can be written or developed from existing ones.
  • 21.
    Example: The Personclass #include<string> #include<iostream> class Person{ char name[20]; int yearOfBirth; public: void displayDetails() { cout << name << " born in " << yearOfBirth << endl; } //... }; private data public processes
  • 22.
    22 The two partsof an object Object = Data + Methods or to say the same differently: An object has the responsibility to know and the responsibility to do. = +
  • 23.
    23 Basic Terminology Abstraction isthe representation of the essential features of an object. These are ‘encapsulated’ into an abstract data type. Encapsulation is the practice of including in an object everything it needs hidden from other objects. The internal state is usually not accessible by other objects.
  • 24.
    24 Basic Terminology: Inheritance Inheritance meansthat one class inherits the characteristics of another class. This is also called a “is a” relationship: A car is a vehicle A teacher is a person A dog is an animal
  • 25.
    25 Basic Terminology: Polymorphism Polymorphism means“having many forms”. It allows different objects to respond to the same message in different ways, the response specific to the type of the object. E.g. the message displayDetails() of the Person class should give different results when send to a Student object (e.g. the enrolment number).
  • 26.
    26 Basic Terminology: Aggregation Aggregation describesa “has a” relationship. One object is a part of another object. We distinguish between composite aggregation (the composite “owns” the part) and shared aggregation (the part is shared by more then one composite). A car has wheels.
  • 27.
    27 Basic Terminology: Behaviour andMessages The most important aspect of an object is its behaviour (the things it can do). A behaviour is initiated by sending a message to the object (usually by calling a method).
  • 28.
    28 The two stepsof Object Oriented Programming Making Classes: Creating, extending or reusing abstract data types. Making Objects interact: Creating objects from abstract data types and defining their relationships.
  • 29.
    29 Historical Notes C++ owesmost to C. Other ancestors are Simula67 and Algol68. First versions of C++ in 1980 under the name “C with classes”. Since 1983 the name C++ is used. 1990: ANSI/ISO 9899 defines a standard for C 1998: ISO/IEC 14882 specifies the standard for C++ C++ 1987
  • 30.
    30 C++ and C Cis a subset of C++. Advantages: Existing C libraries can be used, efficient code can be generated. But: C++ has the same caveats and problems as C (e.g. pointer arithmetic,…). C++ can be used both as a low level and as a high level language. We focus on the high level aspects.
  • 31.
    31 C++ and Java Javais a full object oriented language, all code has to go into classes. C++ - in contrast - is a hybrid language, capable both of functional and object oriented programming. So, C++ is more powerful but also more difficult to handle than Java.
  • 32.
    32 Module Outline Introduction The nonobject oriented basics Classes Design Approaches Testing Inheritance Aggregation Polymorphism Multifile Development
  • 33.
    33 Assessment Details 50% incourse and 50% exam. For more details for the in course assignment see separate handout.
  • 34.
    34 Books Teach Yourself C++in 10 minutes, J. Liberty, SAMS 1999. C++ - How to program, Deitel & Deitel, Prentice Hall, 2001. Object Oriented Programming with C++, David Parson, Letts Educational, London 1997.
  • 35.
    35 Websites A C++ onlinetutorial: http://www.cplusplus.com/doc/tutorial/ The C++ FAQ: http://www.parashift.com/c++-faq-lite The homepage of Bjarne Stroustrup, the inventor of C++: http://www.research.att.com/~bs And many, many more!