oop principles

12
Cutajar & Cutajar Object-Oriented Analysis and Design Introduction

Upload: john-cutajar

Post on 13-Dec-2014

442 views

Category:

Documents


5 download

DESCRIPTION

 

TRANSCRIPT

Page 1: Oop principles

Cutajar

&

Cutajar

Object-Oriented Analysis and Design

Introduction

Page 2: Oop principles

Cutajar

&

Cutajar

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

Page 3: Oop principles

Cutajar

&

Cutajar

State

JohnAge: 32

Height: 6’ 2”

MariaAge: 35

Height: 5’ 10”

JaneAge: 21

Height: 5’ 8”

JoeAge: 35

Height: 5’ 10”

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)..

Page 4: Oop principles

Cutajar

&

Cutajar

Behaviorsit!

return BONE!

eat(drumstick)

Behavior is what the object can

do. That is, the effect of the

object responding to a message

or a call to a method.

Some methods

return something

to the caller

Some methods

need something

from the caller

I said SIT!

Page 5: Oop principles

Cutajar

&

Cutajar

Identity

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.

Page 6: Oop principles

Cutajar

&

Cutajar

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

Page 7: Oop principles

Cutajar

&

Cutajar

InheritanceObject-oriented languages support

some type of inheritance. Many

support inheritance from more

than one parent class. This is

called multiple inheritance. Java

supports only single inheritance,

but allows a class to implement

multiple interfaces.

Human (Super Class)

having common

attributes and

behaviors

Subclasses inherit common features and changes or adds some of their own

Male

Female

Multiple

inheritance

not

permitted

in Java

Baby

Page 8: Oop principles

Cutajar

&

Cutajar

Interface

A Class can implement

various interfaces and

must define methods

used for that interface

Page 9: Oop principles

Cutajar

&

Cutajar

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 !

Page 10: Oop principles

Cutajar

&

Cutajar

Overloading

The method which the object performs is determined by the type and

number of parameters passed to it.

play(guitar)

play(piano)

play(radio)

Page 11: Oop principles

Cutajar

&

Cutajar

Overriding The method in a subclass

hides the method in the

super class. This permits a

redefinition of a method

according to the particular

needs of the subclass

I know how it

should be done

I know how

boys do it.I know how

girls do it.

overridingoverriding

Page 12: Oop principles

Cutajar

&

Cutajar

EncapsulationWe 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 ?