Object-Oriented Programming Concepts

undefined
 
C
h
a
p
t
e
r
 
1
0
I
n
t
r
o
d
u
c
t
i
o
n
 
t
o
 
O
b
j
e
c
t
s
 
a
n
d
 
C
l
a
s
s
e
s
s
 
 
1
 
H
o
w
 
c
a
n
 
o
n
e
 
d
e
s
i
g
n
 
a
 
p
r
o
g
r
a
m
?
 
Top-down structured design
: uses algorithmic decomposition
where each module denotes a major step in some overall
process
 
Object-oriented design
: divides the problem into a set of objects
that interacts to solve the problem. 
Your program
s properties
and 
behaviors
 are modelled based upon real objects like cars,
books, houses, etc.
 
2
 
W
h
y
 
O
O
D
?
 
Software is complex (too many people is doing too many
things – the mess is inevitable 
 )
One of the main goals in programming is to avoid the
redundancy and objects can help to do this (
inheritance
)
Objects can help increase modularity through data hiding
(
encapsulation
)
 
3
 
O
K
,
 
b
u
t
 
w
h
a
t
 
i
s
 
o
b
j
e
c
t
 
?
 
An 
object
 is a thing, either tangible or intangible.
An
 
object-oriented program
 consists of many objects.
An object is composed of 
identity
,
 state
 (attributes, data,
and their current values) and 
behavior
  (operations) .
 
4
 
I
d
e
n
t
i
t
y
,
 
S
t
a
t
e
,
 
B
e
h
a
v
i
o
r
 
Identity is the property of an object that distinguishes it from all
other objects.
The failure to recognize the difference between the name of the
object and the object itself is the source of many errors in object-
oriented (OO) programming.
 
5
 
I
d
e
n
t
i
t
y
,
 
S
t
a
t
e
,
 
B
e
h
a
v
i
o
r
 
The state of an object encompasses all of the (static) 
properties
of the object plus the current (dynamic) 
values
 of each of these
properties
A 
property
 is an inherent or distinctive characteristic, trait, quality,
or feature that contribute to making an object uniquely that
object
We will use the word 
attribute
, or 
data member
, to refer to the
state of an object
 
6
 
E
x
a
m
p
l
e
s
 
o
f
 
S
t
a
t
e
 
Properties
Elevators travel up or down
Vending machines accept coins
Clocks indicate the current time
Values
Current floor
Number of coins deposited
The number of minutes since the last hour
 
7
 
I
d
e
n
t
i
t
y
,
 
S
t
a
t
e
,
 
B
e
h
a
v
i
o
r
 
Behavior
 is how an object acts and reacts, in terms of state
changes and interactions with other objects.
An 
operation
 is some action that one object performs upon
another in order to elicit a reaction.
We will use the word 
method
 to describe object behavior in java.
Invoking
 a method causes the behavior to take place.
 
8
 
C
l
a
s
s
e
s
 
Classes
 are the definitions (or blueprints) used to create objects.
I’d say: 
descriptions 
of objects
.
 
To make a
 
car the manufacturer must first have a design from
which to build the first car.  Then, once all the problems are
worked out, the design is used to build all the cars of that model.
 
9
 
O
b
j
e
c
t
s
 
An 
object
 is an 
instance
 of a class.
 
If we have a class definition called 
Car
, then we can think of
Audi, BMW, and Corvette as each being an instance (object) of
the class 
Car
, i.e., they are each a type of car.
 
10
 
O
b
j
e
c
t
 
e
x
a
m
p
l
e
 
11
 
Audi 6
 
BMW Z3
 
Corvette
 
 Notice that all objects are of the same type. All objects are
cars
!
 
Car
 
Car
 
Car
 
C
l
a
s
s
e
s
 
a
n
d
 
O
b
j
e
c
t
s
 
An object is an instance of exactly one class!!!
Corvette can not be an instance of a car class 
and
 an instance of a
plane class at the same time.
 
An instance of a class, an object, belongs to that particular class.
A Corvette is a car 
 Corvette belongs to the class 
Car
.
 
12
 
C
l
a
s
s
e
s
 
Once a class is defined you can create as many instances of the
class (objects from the class) as you would like.
Once a blue print is completed for the 2003 Porsche 911, Porsche
will use an assembly line to build as many instances of the 2003
Porsche 911 as they wish.
 
13
 
C
l
a
s
s
 
c
a
r
 
a
n
d
 
o
b
j
e
c
t
s
-
 
g
r
a
p
h
i
c
a
l
l
y
 
14
 
Audi 6
 
BMW Z3
 
Corvette
 
Car
 
Car
 
Car
 
Car
This line
shows an
instance-of
relationship.
 
D
e
f
i
n
i
n
g
 
a
 
c
l
a
s
s
 
Properties
  are variables which describe the essential
characteristics of an object.
Properties of a car: 
color
, model, make, how many doors, transmission
type, direction of movement, etc.
Behaviors
 are methods that describe how the object behaves
and how the properties may be modified.
Behavior of a car: braking, changing gears, opening doors, moving
forwards or backwards, etc.
 
15
 
C
l
a
s
s
e
s
 
A
 
c
l
a
s
s
 
i
s
 
a
 
c
o
l
l
e
c
t
i
o
n
 
o
f
 
f
i
e
l
d
s
 
(
d
a
t
a
)
 
a
n
d
 
m
e
t
h
o
d
s
(
p
r
o
c
e
d
u
r
e
 
o
r
 
f
u
n
c
t
i
o
n
)
 
t
h
a
t
 
o
p
e
r
a
t
e
 
o
n
 
t
h
a
t
 
d
a
t
a
.
 
16
 
 
A
d
d
i
n
g
 
F
i
e
l
d
s
:
 
C
l
a
s
s
C
i
r
c
l
e
 
w
i
t
h
 
f
i
e
l
d
s
 
Add 
fields
 
 
 
 
 
 
The fields (data) are also called the varaibles.
 
17
public class Circle {
       
public double x, y;  // centre coordinate
       public double r;     //  radius of the circle
 
}
 
D
a
t
a
 
A
b
s
t
r
a
c
t
i
o
n
 
Declare the Circle class, have created a new data
type – 
Data Abstraction
 
Can define variables (objects) of that type:
Circle  aCircle;
aCircle = new Circle();
OR
Circle bCircle = new Circle();
 
18
Slide Note
Embed
Share

Object-oriented programming (OOP) is a powerful paradigm that helps in organizing and designing programs effectively. This summary covers key aspects such as designing a program, top-down structured design, the importance of OOD, defining objects, identity, state, behavior in OOP, and examples of states in objects.

  • OOP
  • Object-oriented programming
  • Design principles
  • Identity
  • Behavior

Uploaded on Aug 14, 2024 | 2 Views


Download Presentation

Please find below an Image/Link to download the presentation.

The content on the website is provided AS IS for your information and personal use only. It may not be sold, licensed, or shared on other websites without obtaining consent from the author. Download presentation by click this link. If you encounter any issues during the download, it is possible that the publisher has removed the file from their server.

E N D

Presentation Transcript


  1. 1 Chapter 10 Introduction to Objects and Classess

  2. How can one design a program? 2 Top-down structured design: uses algorithmic decomposition where each module denotes a major step in some overall process Object-oriented design: divides the problem into a set of objects that interacts to solve the problem. Your program s properties and behaviors are modelled based upon real objects like cars, books, houses, etc.

  3. Why OOD? 3 Software is complex (too many people is doing too many things the mess is inevitable ) One of the main goals in programming is to avoid the redundancy and objects can help to do this (inheritance) Objects can help increase modularity through data hiding (encapsulation)

  4. OK, but what is object ? 4 An object is a thing, either tangible or intangible. An object-oriented program consists of many objects. An object is composed of identity, state (attributes, data, and their current values) and behavior (operations) .

  5. Identity, State, Behavior 5 Identity is the property of an object that distinguishes it from all other objects. The failure to recognize the difference between the name of the object and the object itself is the source of many errors in object- oriented (OO) programming.

  6. Identity, State, Behavior 6 The state of an object encompasses all of the (static) properties of the object plus the current (dynamic) values of each of these properties A property is an inherent or distinctive characteristic, trait, quality, or feature that contribute to making an object uniquely that object We will use the word attribute, or data member, to refer to the state of an object

  7. Examples of State 7 Properties Elevators travel up or down Vending machines accept coins Clocks indicate the current time Values Current floor Number of coins deposited The number of minutes since the last hour

  8. Identity, State, Behavior 8 Behavior is how an object acts and reacts, in terms of state changes and interactions with other objects. An operation is some action that one object performs upon another in order to elicit a reaction. We will use the word method to describe object behavior in java. Invoking a method causes the behavior to take place.

  9. Classes 9 Classes are the definitions (or blueprints) used to create objects. I d say: descriptions of objects. To make acar the manufacturer must first have a design from which to build the first car. Then, once all the problems are worked out, the design is used to build all the cars of that model.

  10. Objects 10 An object is an instance of a class. If we have a class definition called Car, then we can think of Audi, BMW, and Corvette as each being an instance (object) of the class Car, i.e., they are each a type of car.

  11. Object example 11 Audi 6 BMW Z3 Corvette Car Car Car Notice that all objects are of the same type. All objects are cars!

  12. Classes and Objects 12 An object is an instance of exactly one class!!! Corvette can not be an instance of a car class and an instance of a plane class at the same time. An instance of a class, an object, belongs to that particular class. A Corvette is a car Corvette belongs to the class Car.

  13. Classes 13 Once a class is defined you can create as many instances of the class (objects from the class) as you would like. Once a blue print is completed for the 2003 Porsche 911, Porsche will use an assembly line to build as many instances of the 2003 Porsche 911 as they wish.

  14. Class car and objects- graphically 14 Car This line shows an instance-of relationship. Audi 6 BMW Z3 Corvette Car Car Car

  15. Defining a class 15 Properties are variables which describe the essential characteristics of an object. Properties of a car: color, model, make, how many doors, transmission type, direction of movement, etc. Behaviors are methods that describe how the object behaves and how the properties may be modified. Behavior of a car: braking, changing gears, opening doors, moving forwards or backwards, etc.

  16. 16 Classes A class is a collection of fields (data) and methods (procedure or function) that operate on that data. Circle centre radius circumference() area()

  17. 17 Adding Fields: Class Circle with fields Add fields public class Circle { public double x, y; // centre coordinate public double r; // radius of the circle } The fields (data) are also called the varaibles.

  18. 18 Data Abstraction Declare the Circle class, have created a new data type Data Abstraction Can define variables (objects) of that type: Circle aCircle; aCircle = new Circle(); OR Circle bCircle = new Circle();

More Related Content

giItT1WQy@!-/#giItT1WQy@!-/#giItT1WQy@!-/#giItT1WQy@!-/#giItT1WQy@!-/#giItT1WQy@!-/#giItT1WQy@!-/#giItT1WQy@!-/#giItT1WQy@!-/#giItT1WQy@!-/#giItT1WQy@!-/#giItT1WQy@!-/#giItT1WQy@!-/#