itk 168 lecture 5 - inheritance

6
ITK 168 Lecture 5 - Inheritance

Upload: talon-carpenter

Post on 31-Dec-2015

27 views

Category:

Documents


2 download

DESCRIPTION

ITK 168 Lecture 5 - Inheritance. Examples. Review ExperimentRobot Lamp example. Overriding methods. Overriding occurs when a subclass implements a method of the same name as the superclass causing a change in behavior. Override example. Spinner robot Does 360 spin before turning left - PowerPoint PPT Presentation

TRANSCRIPT

Page 1: ITK 168 Lecture 5 - Inheritance

ITK 168 Lecture 5 - Inheritance

Page 2: ITK 168 Lecture 5 - Inheritance

Examples

• Review ExperimentRobot

• Lamp example

Page 3: ITK 168 Lecture 5 - Inheritance

Overriding methods

• Overriding occurs when a subclass implements a method of the same name as the superclass causing a change in behavior

Page 4: ITK 168 Lecture 5 - Inheritance

Override example

• Spinner robot– Does 360 spin before turning left

• Bad robot– Turns right when supposed to turn left– Turns left when supposed to turn right

Page 5: ITK 168 Lecture 5 - Inheritance

Method Resolution

Robot

void move()

void turnLeft()RobotSE

void turnAround()

void turnRight() BadRobot

void turnLeft()

void turnRight()

Page 6: ITK 168 Lecture 5 - Inheritance

Overriding with side effects

• Speedy