Class-level Methods Chapter 6 part 1. Classes and Objects Classes o In Alice, classes are predefined as 3D models Objects o An object is an instance of.

Slides:



Advertisements
Similar presentations
CS320n –Visual Programming Class-level Methods and Inheritance – Part 1 Mike Scott (Slides 4-3-1) Thanks to Wanda Dann, Steve Cooper, and Susan Rodger.
Advertisements

Class-level Methods Alice. World / Class Method World method A general method that may refer to multiple objects; not closely associated with any particular.
Class-level Methods and Inheritance Part 1 Alice.
Class-level Methods Chapter 6. Class-level Method Is specific to a class of objects We can give a class new abilities/methods Only involves this one class.
Review of Chapter 4 Sections 1 and 2 World-level methods involve two or more objects break a large problem into smaller, logical units follow a design.
Decision Structures Chapter 4. Chapter 4 Objectives To understand: o What values can be stored in a Boolean variable o What sequence structures are and.
Class-level Methods and Inheritance Alice. Class-level Methods Some actions are naturally associated with a specific class of objects. Examples A person.
Class-level Methods and Inheritance MMP 220 Multimedia Programming This adapted material was prepared for students in MMP220 as as part of a curriculum.
CSC1401 Animation Creating methods/instructions (class-level)
Parameters and World-level methods Alice. Our Dragon world The dragon must to take off and fly, to carry the princess.
Events Chapter 7. Interactivity The real world is interactive User determines order of actions instead of programmer.
Events Chapter 7. Interactive Real world is interactive User determines order of actions instead of programmer.
Functions and Visual Effects Chapter 6 Part 3. Built-in Functions We have been using built-in functions so far 2.
Copyright © 2012 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Starting Out with Alice: A Visual Introduction to Programming Third Edition.
Fall 2007ACS-1805 Ron McFadyen1 Functions and if-else A function is a collection of statement, similar to a method, but a function is defined to return.
Fall 2007ACS-1805 Ron McFadyen1 Programming Concepts Chapter 4 introduces more advanced OO programming techniques. Construction of a programs usually requires:
Alice: A Visual Introduction to Programming Chapter 1 Part 2.
Programming in Alice Chapter 2 Part 2. Events Editor Identifies what method is executed (run) when the “Play” button is hit 2.
Classes, Objects, and World-level Methods Alice. Programming in Alice© 2006 Dr. Tim Margush2 Class / Object Class A template describing the characteristics.
Copyright 2011 Wanda Dann, Steve Cooper, Don Slater Alice Workshop Implementation Algorithm  Code World.my first method Control blocks Statements (methods,
Fall 2007ACS-1805 Ron McFadyen1 Chapter 4 OO Programming Concepts.
Fall 2008ACS-1805 Ron McFadyen1 Programming Concepts Chapter 4 introduces more advanced OO programming techniques. Construction of a programs usually requires:
Methods Tutorial: Part One By Deborah Nelson Duke University Under the direction of Professor Susan Rodger June 9, 2008.
METHODS!.  A method is a sequence of instructions or behaviors that will be carried out when requested.  You can use them to create new methods so that.
Classes / Objects / Methods
Variables and Functions Chapter Variables Named storage location in computer’s memory Programs may need to store data when running o Stored in.
Classes, Objects, and World-level Methods
Today’s Agenda 1.Collect Pre-Lab 4 2.Alice Programming Assignment Storyboards 3.Classes 4.Objects 5.Methods 6.Assign pair programming teams and meet upstairs.
Classes, Objects, and World-level Methods Alice. Larger Programs As you become more skilled in writing programs, you will find that programs quickly increase.
Classes, Objects, and World-level Methods Section 47 Web Design.
Classes, Objects, and World-level Methods Alice. Larger Programs As you become more skilled in writing programs, you will find that programs quickly increase.
Decision Structures Chapter 4 Part 2. Chapter 4 Objectives To understand o What relational operators are and how they are used o Boolean logic o Testing.
Events Chapter 7 Part 2. While a Key is Pressed Event Specialized event An event occurs when you press a key and continues until you take your finger.
Alice 2.0 Introductory Concepts and Techniques Project 1 Exploring Alice and Object-Oriented Programming.
Teaching a character to walk in more than one world: Parameters and Inheritance. By Lana Dyck under the direction of Professor Susan Rodger Duke University.
Alice: A Visual Introduction to Programming Chapter 1 Part 2.
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Where are we? Alice is a “toy” language Fundamentals are exactly like “real”
Methods Tutorial: Part Two By Deborah Nelson Duke University Professor Susan Rodger June 16, 2008.
Now that the kangaroo and the turtle have raced, let's make a method for the kangaroo to hop back to the turtle and challenge him to a race again. Click.
Writing Our Own Functions Alice. Functionality A function receives value(s), performs some computation on the value(s), and returns (sends back) a value.
Functions Alice.
Classes, Objects, and World-level Methods Alice. Larger Programs As you become more skilled in writing programs, you will find that programs quickly increase.
Variables and Inheritance Part 1
Variables and Functions Chapter Variables Named storage location in computer’s memory Programs may need to store data when running Types of data.
Balancing the scales: Inequalities By Melissa Dalis Professor Susan Rodger Duke University June 2011.
Classes, Objects, and World-level Methods MMP 220 Multimedia Programming This adapted material was prepared for students in MMP220 as as part of a curriculum.
Variables and Functions Alice. Naming is Important If you get a new pet one of the first things you do is name it Gives you a way to refer to the new.
Functions Sec 8-11 Web Design. Objectives The Student will: Understand what a function is Know the difference between a method and a function Be able.
Questions Alice. Functionality A question receives value(s), performs some computation on the value(s), and returns (sends back) a value.
Class-level Methods and Inheritance Alice. Class-level Methods Some actions are naturally associated with a specific class of objects. Examples A person.
World-level Classes Chapter 6 Part 2. Programs Grow Program code grows larger over time This makes it more difficult to read and process the code in our.
CompSci 4 Chap 4 Sec 3 Sept 23, 2010 Prof. Susan Rodger.
Using Placeholders to Simplify your Methods: Learning Methods, Part 2 By Deborah Nelson Duke University Professor Susan Rodger June 16, 2008.
Presenter: Carol Liss Timberlane Regional Middle School 6 th and 7 th grade Tech. Educator Co presenters:
An Introduction to Programming Using Alice 2.2, Second Edition Chapter 7 Recursive Algorithms.
Class-level Methods and Inheritance Alice. Class-level Methods Some actions are naturally associated with a specific class of objects. Examples A person.
Variables and Inheritance Part 1 Alice. Review: Properties A class defines properties for its own kind of object. When an object is created (instantiated),
1 Quiz Show Programming Terms. 2 Alice - 3D Virtual Programming Vocabulary Quiz Board Chapter 1 Chapter 2a Chapter 2b Chapter 3 Chapter 4 $100 $200 $300.
Classes, Objects, and World-level Methods
Classes, Objects, and World-level Methods
Classes, Objects, and World-level Methods
Classes, Objects, and World-level Methods
CS320n –Visual Programming
Class-level Methods Alice.
Classes, Objects, and World-level Methods
Parameters and World-level methods
Classes / Objects / Methods
Classes, Objects, and World-level Methods
Class-level Methods and Inheritance
Class-level Methods and Inheritance Part 2
Presentation transcript:

Class-level Methods Chapter 6 part 1

Classes and Objects Classes o In Alice, classes are predefined as 3D models Objects o An object is an instance of a class Class: Frog (Uppercase first letter) Objects: frog, frog1, frog2, frog3 (lowercase first letter) 2

Methods Built-in (predefined) methods o Examples: move, turn to face, say Custom methods o User created method o Does something that was not predefined in Alice 3

Class-level Method Is specific to a class of objects We can give a class new abilities/methods Only involves this one class level object Examples o A person walking o A skater skating Unlike world class-level methods o Which has access to multiple classes 4

Example Skater object does not have a skate method To create a skate method for ice skater objects We need to: (1)Tell Alice to associate a new method with iceSkater class (2)Write a new method to animate ice skater skating 5

Associate Animation with Skater Select iceSkater tile in Object Tree Select methods tab in details panel Click on create new method button 6

Algorithm for skate Method Each slide action requires several motion instructions These actions need to be broken down into smaller steps using stepwise refinement skate: Do together move skater forward 2 meters Do in order slide on left leg slide on right leg 7

Stepwise Refinement Process of breaking problem into smaller tasks o Makes large task more manageable Break each task into simpler steps Once algorithm is completed write a method for each task 8

Stepwise Refinement For skate Refinement of slideLeft Do in order Lift right leg and turn upper body forward Lower right leg and return body upright skate: Do together 1) move forward 2 meters 2) Do in order slideLeft slideRight Refinement of slideRight Do in order Lift left leg and turn upper body forward Lower left leg and return body upright 9

Alice Programs for skate Algorithm Notice how skate is preceded by icekater instead of world like World.my first method 10

Demonstration Concepts illustrated o Method defined for a specific type of object defines action for that object o A method can call other methods skate method calls slideRight and slideLeft 11

Class Methods Allow Reuse Writing methods that make ice skater perform skating motion is a complex task Would like to reuse iceSkater skate in other worlds without writing methods again 12

Creating A New Class 1)Rename iceSkater as cleverSkater either a)Double click object name b)Or right click name 2)Right click name to save as a new class 3)Alice saves new class as CleverSkater.a2c Alice v2 Class 13

Importing CleverSkater An instance of the CleverSkater class can be added to a new world o Use File | Import o Set File Type to A2C o Choose class file to import 14

Interacting With Other Objects Suppose you want to write a class-level method where another object is involved? Ex: a method to make skater skate around another object, like the penguin in this scene o It can be anything, like lake, cone, etc. 15

Parameters Built-in methods give flexibility by providing parameters like distance and direction Parameters allow values (arguments) to be passed to methods o Example  Parameters: direction, distance, duration  Arguments: up, 0.5 meters, 0.5 seconds  Where duration is optional Alice provides several kinds of parameters that can be used in custom methods o Number, Boolean, Object, Other 16

Parameters in Class-level Method Solve skate around object by writing a class-level method with an object parameter Allows you to pass a specific object cleverSkater.skateAround Parameter: whichObject Do in order Do together cleverSkater turn to face whichObject cleverSkater lift right leg cleverSkater move to whichObject cleverSkater turn around whichObject 17

Parameters Are Placeholders A value is passed to a method with an argument Parameters act as placeholders for the argument o Takes value of argument being passed to method and uses it in method using parameter’s name o Parameter name is usually different than argument Example: in move method o You pass arguments that are specific direction and distance to move (ex: up, 0.5 meters) o Those specific arguments are passed to the move method’s parameters (direction and distance) 18

Creating Parameters Create parameter using create parameter whichObject is passed as Object parameter Notice how skate is preceded by iceskater instead of world like World.my first method 19

Guidelines To avoid potential misuse of class-level methods follow these guidelines o Avoid references to other objects  Use parameters if referencing another object is required o Avoid calls to world-level methods  Will not be saved with new class you created o Play a sound only if sound has been imported and saved out as part of new class 20

Demonstration Concept illustrated o Parameter whichObject is placeholder for the object value passed to it  Ex: penguin 21

Class-Level Variables as Properties  A property is a variable that belongs to an object  Properties can be added to an object through the creation of class-level variables  When the object is saved as a new class the variables are saved with it  Common properties are o color o opacity o isShowing 22

Tutorial 6-5: Turn Monitor On/Off A new property is added to monitor: is monitor on or off? Create class-level variable that keeps track of state of computer monitor: on or off On Off 23

Algorithm to Turn Monitor On/Off If monitor is off then turn it on If it is on then it will turn it off 24 turnOnOff Do in order If monitor isOn set screen color to black set isOn variable to false Else set screen color to no color set isOn variable to true Endif

Algorithm Translated to Alice Notice how new method is preceded by monitor not world o Means it is a class-level method not world-level o Will be saved if class is saved o If world is saved the class will not be saved for future use in other programs  Can only use this in this new method in this specific program notice variable is preceded by monitor 25

Using turnOnOff Method Variable monitor.isOn is set initially to true In world.My first method o Turn off monitor using turnOnOFF  Variable monitor.isOn is now set to false o Wait 1 second to see effect o Turn on monitor using turnOnOFF 26

Homework Read chapter 6 sections Do tutorials 1 – 5 Do exercise in handout Due one week after assigned with 1 week grace 27