Beruflich Dokumente
Kultur Dokumente
Object-Oriented Programming
Agenda
Structured programming vs. OO programming
Structure and classes in c++
Why OOPs?
Features of OOPs
Abstraction
Encapsulation
Polymorphism
Inheritance
STRUCTURED PROGRAMMING:
MAIN PROGRAM
FUNCTION
1
FUNCTION 4
FUNCTION 2
GLOBAL DATA
FUNCTION 3
FUNCTION 5
Object 1
Data
Data
Function
Function
Object 3
Data
Function
Therealworldcanbeaccuratelydescribedasacollectionof
objectsthatinteract.
5
buffer::enter(char x) {
// body of enter }
char buffer::leave() {
// body of leave }
Why OOP?
Easier debugging
classes can be tested independently
reused objects have already been tested
16
Data Abstraction.
Encapsulation.
Information Hiding.
Polymorphism (dynamic binding).
Inheritance.
Object-Oriented Programming
Object-oriented programming is a programming
methodology characterized by the following concepts:
1. Data Abstraction: problem solving via the formulation
of abstract data types (ADT's).
2. Encapsulation: the proximity of data definitions and
operation definitions.
3. Information hiding: the ability to selectively hide
implementation details of a given ADT.
4. Polymorphism: the ability to manipulate different kinds
of objects, with only one operation.
5. Inheritance: the ability of objects of one data type, to
inherit operations and data from another data type.
C++ Construct(s)
Abstraction
Encapsulation
Information Hiding
Polymorphism
Classes
Classes
Public and Private Members
Operator overloading,
templates, virtual functions
Derived Classes
Inheritance
Abstraction
Focus only on the important facts about the
problem at hand
to design, produce, and describe so that it can
be easily used without knowing the details of
how it works.
Analogy:
When you drive a car, you dont have to know
how the gasoline and air are mixed and ignited.
Instead you only have to know how to use the
controls.
Draw map
20
Encapsulation
Also known as data hiding
Only objects methods can modify
information in the object.
Analogy:
ATM machine can only update accounts
of one person or object only.
21
Polymorphism
the same word or phrase can mean
different things in different contexts
Analogy:
Person role
In English, bank can mean side of a river
or a place to put money
move -
22
Inheritance
Inheritancea way of organizing classes
Term comes from inheritance of traits like
eye color, hair color, and so on.
Classes with properties in common can be
grouped so that their common properties
are only defined once.
Superclass inherit its attributes &
methods to the subclass(es).
Subclass can inherit all its superclass
attributes & methods besides having its own
23
unique attributes & methods.
An Inheritance Hierarchy
Superclass
Vehicle
Subclasses
Automobile
Sedan
Motorcycle
Sports Car
Luxury Bus
Bus
School Bus
What properties does each vehicle inherit from the types of vehicles above it
in the diagram?
24