2/8/2012
Lecture 12: Object Oriented Programming
Introduction to Computer
Programming for Engineering
Lecture 12: Object Oriented Programming
WHAT IS OOP?
1
2/8/2012
What is a OOP?
A programming paradigm that uses
"objects" – data structures consisting of
data fields and methods together with
their interactions – to design applications
and computer programs..
Programming Paradigm
A programming paradigm is a fundamental
style of computer programming.
Compare with a methodology, which is a
style of solving specific software
engineering problems.
2
2/8/2012
OOP compared to Procedural
Programming
The focus of object-oriented
programming it is to break down a
programming task into objects with each
"object" encapsulating its own data and
methods (subroutines).
Lecture 12: Object Oriented Programming
WHAT IS AN OBJECT?
3
2/8/2012
What is an Object?
A discrete bundle of functions and
procedures, often relating to a particular
real-world concept such as a teacher or
student.
Lecture 12: Object Oriented Programming
FUNDAMENTAL
CONCEPTS
4
2/8/2012
Class
A user defined datatype which contains
the variables, properties and methods in
it.
Class
A class defines the abstract
characteristics of a thing (object),
including its:
◦ Properties
◦ Methods
5
2/8/2012
Class
• Characteristics
Properties • Attributes
• Behaviors
Methods • Functions /
Operations
Class
For example, the class Dog would consist
of traits shared by all dogs such as:
◦ breed and fur color (properties)
◦ the ability to bark and sit
(methods/behavior).
6
2/8/2012
Instance
The Instance is the ACTUAL OBJECT
created at run-time
Instance
For example, the Akamaru object is an
instance of the Dog class.
7
2/8/2012
Method
Method is a set of procedural statements
for achieving the desired result.
It performs different kinds of operations
on different data types.
In a programming language, methods
(sometimes referred to as "functions") are
verbs.
Method
Akamaru, being a Dog, has the ability to
bark. So bark() is one of Akamaru's
methods.
She may have other methods as well, for
example
◦ sit()
◦ eat()
◦ walk()
◦ save(Timmy).