chapter 4: classes, objects, and parameters 4.1 world-level methods

17
Chapter 4: Classes, Objects, and Parameters 4.1 World-Level methods

Upload: fay-kelley

Post on 01-Jan-2016

236 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Chapter 4: Classes, Objects, and Parameters 4.1 World-Level methods

Chapter 4: Classes, Objects, and Parameters

4.1 World-Level methods

Page 2: Chapter 4: Classes, Objects, and Parameters 4.1 World-Level methods

Chapter 4.1

• Learning Goal: Technical analysis and communication skills– Tutors help you “ask yourselves the right

questions”

Page 3: Chapter 4: Classes, Objects, and Parameters 4.1 World-Level methods

What do you get from this course?

• Analysis skills – – Practiced and refined in your group discussions!

We learned in Alice that computers do exactly what you have them do.  Using this knowledge,

we can understand how programs like Excel and Numbers work and learn that when we are using these programs, we need to specify and be exact with what we are doing in order for the programs to meet our needs and plans.

Page 4: Chapter 4: Classes, Objects, and Parameters 4.1 World-Level methods

Clicker Discussion Analysis Technique:

• Begin at the beginning:– Are you reading the question the “same way”?– What is the question asking for?

• TRY THESE:– “So what I think this is asking is”– “It seems like the idea here is whether we can

identify the differences in these codes”– “We need to figure out how to correct this code to

do X instead of Y”

Page 5: Chapter 4: Classes, Objects, and Parameters 4.1 World-Level methods

What is the best explanation of why we divide code into methods?

A. In order to be able to put a name on themB. In order to break work into manageable

piecesC. So it can be stored more efficientlyD. So that each object can have “actions” they

do

Page 6: Chapter 4: Classes, Objects, and Parameters 4.1 World-Level methods

What term do we use to describe the indicated area below

A. Method call B. Method definition

Page 7: Chapter 4: Classes, Objects, and Parameters 4.1 World-Level methods

When you hit Play Alice will by default*:

A. Runs World.My first methodB. Starts by running whatever method you

created firstC. Starts by running whatever method you

created lastD. Runs all the methods in the order they

appear in the methods tabE. None of the above

*Assuming you don’t modify any of the events in the upper right corner

Page 8: Chapter 4: Classes, Objects, and Parameters 4.1 World-Level methods
Page 9: Chapter 4: Classes, Objects, and Parameters 4.1 World-Level methods

The First Encounter World

• In chapter 2 you developed the first encounter world and created the following code…

Page 10: Chapter 4: Classes, Objects, and Parameters 4.1 World-Level methods
Page 11: Chapter 4: Classes, Objects, and Parameters 4.1 World-Level methods

Step-wise refinement• Break the work up into three methods– Call those methods from my first method

Page 12: Chapter 4: Classes, Objects, and Parameters 4.1 World-Level methods

One should use methods in programs primarily…

A. For the computerB. For the person writing the programC. For people reading a programD. More than one of the above

And WHY is it important?

Page 13: Chapter 4: Classes, Objects, and Parameters 4.1 World-Level methods

How to “make” methods

• Think of ways in which your planned animation has natural “parts”– Give each of the parts a name– Put the code that makes that “part” happen in a

method with that name– Call that method from my first method, in the

right order.

Page 14: Chapter 4: Classes, Objects, and Parameters 4.1 World-Level methods

Example: Going to a movie…

• Walk up to ticket window– Walking in group

• Buy tickets– Interact with ticket seller (talking, hand over money, get

tickets)• Enter theater– Walk through doors, hand tickets to worker, walk into lobby

• Buy snacks…• Take seats…• Make snarky critiques…• …

Page 15: Chapter 4: Classes, Objects, and Parameters 4.1 World-Level methods

Below shows an example of the benefits of using methods because it allows the

programmer to…

A. Comment methods to further explain what they doB. Re-order the parts of the animation with little extra

workC. Repeat a set of instructions with little extra work

Page 16: Chapter 4: Classes, Objects, and Parameters 4.1 World-Level methods

Below: what happens after the last instruction in the mystery method is finished executing?

A. The program starts the World.my first methodB. The program goes back to my first method and calls

method XXXXXC. The program goes back to my first method and calls

method YYYYYD. We can’t tell, we need to know more about the

storyboard to be able to say

Page 17: Chapter 4: Classes, Objects, and Parameters 4.1 World-Level methods

Methods: Why again?

• Break complex things into smaller, more manageable pieces (step-wise refinement)– Do something more than once…

• Do something more than once, but not exactly the same each time– Parameters allow you to write code one time but

have it be useful in various circumstances• where the “thing” involved could be different each time