Methods

19
Methods Alice May 30, 2012

description

Methods. Alice May 30, 2012. Larger Programs. As you become more skilled in writing programs, you will find that programs quickly increase to many, many lines of code. Games and other "real world" software applications can have thousands, even millions of lines of code. Potential Problem. - PowerPoint PPT Presentation

Transcript of Methods

Page 1: Methods

Methods

Alice

May 30, 2012

Page 2: Methods

Larger Programs

As you become more skilled in writing programs, you will find that programs quickly increase to many, many lines of code.

Games and other "real world" software applications can have thousands, even millions of lines of code.

Page 3: Methods

Potential ProblemThe program code just seemed to grow and grow.

If we continue to write programs this way the programs will become longer and more difficult to read and think about.

Page 4: Methods

Methods

Object-oriented programming uses classes, objects, and methods as basic programming components.

These components help to organize a large program into small modules

design and think about an intricate program

find and remove errors (bugs)

Page 5: Methods

Why?Why do we want to write our own methods?

saves time -- we can call the method again and again without reconstructing code

reduces code size – we call the method rather than writing the instructions again and again

allows us to "think at a higher level"can think surprise instead of

“The alien moves up and says ‘Slithy toves?’ and then the robot's head turns around. "

the technical term for "think at a higher level" is "abstraction"

Page 6: Methods

We can use…built-in (predefined) methods

Examples: move, turn to face, say

your own method (you created the method)

Examples: Spin, Wink, Skate

Page 7: Methods

Ice Skater spin method example

Page 8: Methods

Demo: Starting a new method

First, to associate the new method with the World

• select the World tile in the Object Tree

•select the methods tab in the details area

•click on the "create new method" button

Page 9: Methods

How to write a Method:

Steps to writing Methodscreate them

call them

Page 10: Methods

Today’s Program

Open Alice

Create your skater program.

Page 11: Methods

Let’s create our coding

Page 12: Methods

Create new method:

Page 13: Methods
Page 14: Methods
Page 15: Methods
Page 16: Methods
Page 17: Methods
Page 18: Methods
Page 19: Methods

That’s it!

Play your program – does it work.

Press W and space bar.

Does your skater spin and wink?