Class-level Methods Alice.

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.
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.
World-level Methods with Parameters Alice. Larger Programs As you become more skilled in writing programs, you will find that your programs quickly begin.
Repetition Structures
Fall 2008ACS-1805 Ron McFadyen1 Programming Concepts Chapter 4 introduces more advanced OO programming techniques. Construction of a programs usually requires:
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 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.
Classes, Objects, and World-level Methods Alice. Programming in Alice© 2006 Dr. Tim Margush2 Class / Object Class A template describing the characteristics.
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.
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.
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.
Alice 2.0 Introductory Concepts and Techniques Project 1 Exploring Alice and Object-Oriented Programming.
Poses Tutorial Alex Boldt Under the direction of Professor Susan Rodger Duke University July 2015.
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.
Parameters and Event-Handler Methods Alice. Mouse clicks Interactive programs often allow the user to mouse click an object in the display. buttons in.
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Where are we? Alice is a “toy” language Fundamentals are exactly like “real”
By Deborah Nelson Duke University Professor Susan Rodger July 13, 2008.
Classes, Objects, and World-level Methods Alice. Larger Programs As you become more skilled in writing programs, you will find that programs quickly increase.
Programming: Simple Control Structures Part 2 – Repetition Alice.
The Essentials of Alice Mrs. Jayne Slease SBMS CTE Computer Science and Animation Credit to Duke Students under the direction of Professor Susan Rodger.
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.
Headshots in Alice Duke University Professor Susan H. Rodger Gaetjens Lezin July 2008.
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
Setting Up the Initial Scene
Classes, Objects, and World-level Methods
Learn about functions in Alice
Teaching Characters to Walk: Learning Methods, Part 1
Classes, Objects, and World-level Methods
Making Objects Move in Unison: Using Lists
Classes, Objects, and World-level Methods
Classes, Objects, and World-level Methods
World-level Methods with Parameters
Learning Java with Alice 3.0 Game Design Kathy Bierscheid
CS320n –Visual Programming
Alice and Media Computation August 2009
Classes, Objects, and World-level Methods
Making Objects Move in Unison: Using Lists
Alice in Action with Java
Classes, Objects, and World-level Methods
Making Procedural Methods
Parameters and World-level methods
Making Objects Move in Unison: Using Lists
Headshots in Alice Duke University Professor Susan H. Rodger
Classes / Objects / Methods
Making Objects Move in Unison: Using Lists
Classes, Objects, and World-level Methods
Class-level Methods and Inheritance
Class-level Methods and Inheritance Part 2
Presentation transcript:

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 Class method A method belonging to a class, designed to operate on an object of that class

Animated Actions Some actions are more naturally associated with a specific class of objects rather than with the overall world. Examples A person walking A wheel rolling A fish swimming

Class Level Methods These methods apply to a particular class of objects They are included as part of the class template Some classes have such methods (beyond the primitive methods expected of all objects) Every instance of the class has such a method Create class level methods (functions) to extend the functionality of the class

Class-level Methods We can write our own methods to add abilities/functions to a specific class of objects This will result in a class-level rather than a world-level method The next few slides will demonstrate how to build class-level methods

Primitive / User-defined Methods Primitive methods those directly provided by the classes that are part of the Alice system move, turn, distanceTo, … User-defined methods (and functions) those added to a world or class as part of a program These consist of collections of primitive and other user-defined methods

A Predefined Class Method Mana (Local Gallery>People) has two predefined methods These are different from built-in methods because you can edit them Every instance of the Mana class has these methods Predefined methods Note Edit button

Designing Class Level Methods Be sure it will apply to all objects of the specific class World level methods implement general functionality that can be applied to many different types of objects Class level methods will apply to all objects of the class Each object created from the class will include the new methods

Argument / Parameter Argument Parameter A piece of information passed to a method or function that will be used in its computations World.jump(who = Rabbit) // Rabbit is the Argument Parameter A placeholder for information passed to a method (or function) by the caller; provides a handle (name) by which the information is referred to in the method In method definition: World.jump(who) // who is the parameter who move up 1 meter

An example (building technique) How can we create a skate method for ice skater objects? We need to: tell Alice to associate the new method (the one we are about to write) with an ice skater, and write a new method to animate the ice skater skating.

Demo: The solution First, to associate the animation with the ice skater select the iceSkater tile in the Object Tree select the methods tab in the details area click on the "create new method" button

Storyboard for skate Skate: Do together move skater forward 2 meters Do in order slide on left leg slide on right leg The slide actions each require several motion instructions, so we will break these two actions down into smaller pieces… this technique is called stepwise refinement

Refined storyboard 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

Writing the code The next step is to translate the design into program code. For the slideLeft method, a possible translation is: Design step Instruction Lift the right leg turn the right thigh forward Turn upper body forward turn the abs forward Lower the right leg turn the right thigh backward Return the body upright turn the abs backward

Demo Demonstration of slideLeft slideRight skate

Correspondence of design to code Skate: Do together move skater forward 2 meters Do in order slide on left leg slide on right leg

Question Writing the methods to make an ice skater perform a skating motion is an intricate task. Most likely, you would like to reuse these new methods in other worlds. How can you make the skate method available for an ice skater in a different world?

Answer: Save out as a new class 1) Rename iceSkater as cleverSkater. 2) Save out as a new class. Alice saves the new class as CleverSkater.a2c

Creating a Class in Alice Choose a class as a base class Your new class will inherit everything from the base class Create an object of the base class Add properties, methods, and functions to the object's details Test! Save the object as a new 3D class model

Using CleverSkater An instance of the CleverSkater class can be added to a new world – use File|Import.

Benefits of Creating a Class New Classes supports the reuse of program code -- allows the programmer to write code once and use it again later in different programs. sharing code with others in a team project

Class Methods No-No's Class-level methods should be closely related to an object of the class If not, consider making the method a world- level one, or place it in another class Programming in Alice © 2006 Dr. Tim Margush

Class Methods No-No's Do not make methods too large Instead, use step-wise refinement Create smaller methods to accomplish the subtasks needed for more complex tasks Programming in Alice © 2006 Dr. Tim Margush

Class Methods No-No's Do not refer to other objects in your class- level methods Those objects may not exist in another world Camera and world objects are a possible exception to this rule Instead, create a parameter (of type object) and refer to the object in a more general sense Programming in Alice © 2006 Dr. Tim Margush

Assignment Read Chapter 4-3 Read Tips & Techniques 4 Class-level methods and Inheritance Read Tips & Techniques 4 Visible and Invisible Objects