2. What is an Object?
An object has…
State
◦ Changes over time
Behavior
◦ What the object does in response to messages
Identity
◦ What makes the object unique
Cutajar
&
Cutajar
3. State
Not only do these people look different, they have different properties (also
called attributes) that let us tell one from the other. Some of the properties
that a person might have are name, age, height, and so on. Some of these,
like age, might change (are mutable) and some, like name, might never
change (are immutable)..
John Maria
Age: 32 Age: 35
Height: 6’ 2” Height: 5’ 10”
Cutajar
&
Cutajar Jane Joe
Age: 21 Age: 35
Height: 5’ 8” Height: 5’ 10”
4. Behavior
sit! Behavior is what the object can
do. That is, the effect of the
object responding to a message
or a call to a method.
return BONE! Some methods
return something
to the caller
Cutajar eat(drumstick)
& I said SIT!
Cutajar
Some methods
need something
from the caller
5. Identity
Cutajar
&
Cutajar Usually, one can tell one object from another through some
combination of the properties. In fact, there MUST be some way
of telling one object from another. Java uses the object’s
address.
6. Classes
Define the properties and behavior of objects
Can have behavior and properties that are defined in the class but are
independent of the individual objects
Cutajar
&
Cutajar
7. Inheritance Object-oriented languages support
some type of inheritance. Many
support inheritance from more
than one parent class. This is
Human (Super Class)
called multiple inheritance. Java
having common
supports only single inheritance,
attributes and
but allows a class to implement
behaviors
multiple interfaces.
Multiple
inheritance
Cutajar
not
& permitted
Cutajar Male in Java
Female Baby
Subclasses inherit common features and changes or adds some of their own
8. Interface
Cutajar
&
Cutajar A Class can implement
various interfaces and
must define methods
used for that interface
9. Polymorphism
Different type of objects can respond to the same message
The actual method that executes is not determined until run time
◦ Dynamic (or late) binding
PLAY !
Cutajar
&
Cutajar
10. Overloading
The method which the object performs is determined by the type and
number of parameters passed to it.
play(radio)
Cutajar
& play(guitar)
Cutajar
play(piano)
11. Overriding
The method in a subclass
hides the method in the
super class. This permits a
redefinition of a method
I know how it according to the particular
should be done needs of the subclass
overriding overriding
I know how I know how
boys do it. girls do it.
Cutajar
&
Cutajar
12. Encapsulation
We are hiding the implementation details of
a behavior. The way an object responds to
a message is not exposed, just the fact
that it can respond and the result type
(response). One of the biggest advantages
of O-O is the ability to make changes to an
object’s implementation without affecting
other parts of the program.
How did he do
that ?
Cutajar
&
Cutajar