Classes / Objects / Methods

Slides:



Advertisements
Similar presentations
Class-level Methods Alice. World / Class Method World method A general method that may refer to multiple objects; not closely associated with any particular.
Advertisements

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.
Alice Inheritance and Event Handling. Inheritance Concept Consider this hierarchy; parents describe properties of children Animals Vertebrates MammalsFish.
Alice Methods and Classes. Methods and Classes Methods – Coordinated sequence of instructions carried out when requested (e.g. move, turn to, etc.) Class.
World-level Methods with Parameters Alice. Larger Programs As you become more skilled in writing programs, you will find that your programs quickly begin.
Copyright © 2012 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Starting Out with Alice: A Visual Introduction to Programming Third Edition.
About the Presentations The presentations cover the objectives found in the opening of each chapter. All chapter objectives are listed in the beginning.
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,
Creating a 3D Interactive Story Prof. Susan Rodger Duke University Feb. 24, 2007.
Classes / Objects / Methods
01-Intro-Object-Oriented-Prog-Alice1 Barb Ericson Georgia Institute of Technology Aug 2009 Introduction to Object-Oriented Programming in Alice.
Scratch the Cat. Object Oriented Programing Writing computer programs Based on Objects Instead of Actions Based on Data Instead of Logic.
Variables and Functions Chapter Variables Named storage location in computer’s memory Programs may need to store data when running o Stored in.
A First Program Using C#
Classes, Objects, and World-level Methods
Programming Logic Program Design. Objectives Steps in program development Algorithms and Pseudocode Data Activity: Alice program.
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.
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.
Creating An Animation Program Part 2 Alice. Method A segment of program code (instructions) that defines how to perform a specific task.
CS329e – Elements of Visual Programming Implementing Programs Mike Scott (Slides 2-2)
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.
Animation Programs: Scenarios and Storyboards Alice.
Alice: A Visual Introduction to Programming Chapter 1 Part 2.
Xin Nov 15, Introduction to Alice Alice A very visible programming language Programming by dragging objects Interface World window The virtual world.
Creating Buttons – Lesson 71 Creating Buttons Lesson 7.
Identifiers Identifiers in Java are composed of a series of letters and digits where the first character must be a letter. –Identifiers should help to.
CompSci 4 Chap 4 Sec 1 Sept 15, 2005 Prof. Susan Rodger.
1.
CS320n –Visual Programming Classes, Objects, and World- Level Methods Mike Scott (Slides 4-1)
Creating a 3D Interactive Story Prof. Susan Rodger Duke University July 19, 2007.
Methods (part 2) Alice In Action, Ch 2 Slides Credit: Joel Adams, Alice in Action CS 120 Lecture 03 4 September 2012.
Class-level Methods and Inheritance Alice. Class-level Methods Some actions are naturally associated with a specific class of objects. Examples A person.
Program Organization Sequential Execution: One line done after the other Conditional Execution: If a test is true, one section is done, otherwise another.
CompSci 4 Chap 4 Sec 3 Sept 23, 2010 Prof. Susan Rodger.
Programming in Alice IT-IDT-9 Design, develop, test and implement programs using visual programming. 9.1 Utilize drag and drop software to develop programs.
Creating a Fancier Chicken to use in several worlds - Inheritance Susan Rodger Duke University June 2009.
What About Alice? In Alice, we have seen that we have:  Objects (skater, snowman, snowwoman, camera)  Methods (move, turn, roll, move toward)  Properties.
Chapter 2: Programming in Alice
Class-level Methods and Inheritance Alice. Class-level Methods Some actions are naturally associated with a specific class of objects. Examples A person.
Classes, Objects, and World-level Methods
Classes, Objects, and World-level Methods
Classes, Objects, and World-level Methods
Classes, Objects, and World-level Methods
Classes, Objects, and World-level Methods
Programming Logic Alice.
World-level Methods with Parameters
Learning Java with Alice 3.0 Game Design Kathy Bierscheid
Introduction to Object-Oriented Programming
Classes, Objects, and World-level Methods
Class-level Methods Alice.
Alice in Action with Java
Alice in Action with Java
Classes, Objects, and World-level Methods
Making Procedural Methods
Alice Variables Pepper.
Chapter 2: Programming in Alice
Creating an Animation Program
Introduction to Object-Oriented Programming in Alice
ICT Gaming Lesson 3.
Workshop for Programming And Systems Management Teachers
Classes, Objects, and World-level Methods
Creating An Animation Program
Class-level Methods and Inheritance
Agenda for Unit 3: Functions
Presentation transcript:

Classes / Objects / Methods Chapter 4

Object Oriented Programming Divides a program into Modules/Classes Uses Classes and Objects to simulate real world environments Basic Programming Components Classes Objects Methods

Class Specifies the definition of a particular kind of object Frog Snowman Cell phone Blueprint / design for how to create an object of that type Class names begin with a Capital letter Alice objects are 3-D models.

Class Properties Characteristics Methods Behaviors

Objects Specific Instances of a Class Implementation of the Class Definition Spot  one specific dog Frosty  one specific snowman All specific objects of the same class share the same definition Same Properties – can be modified Same Methods – can be modified Object names begin with lowercase letter Ob

Dog Object All Instances of Class Dog Have Each Instance Has Properties Name Breed Weight Color Methods Walk Bark Jump Each Instance Has Properties Spot Mutt 10 pounds Black Methods Walk Bark Jump (can be modified to fit Spot’s requirements)

Methods Sequence of Instructions Tasks that can be performed Some are predefined within the Class Dog has a bark method Others are Created or Modified Methods organize the program Divide the program into manageable pieces

Parameters Pieces of Information that need to be sent to the Method Turn Toward (what) Turn Toward Snowwoman Methods are like a series of instructions  Recipe Parameters are the Specifics for that Recipe  how much water to add

Levels of Methods Global Methods (World Level) Class Methods Methods that reference more than one object Class Methods Methods that define a behavior for one single object

Create New Method Snowpeople (problem 4-1) World Method flipsHat Raises right arm Grabs Hat Tips toward snowwoman Returns Hat to Head World Method Uses snowman and snowwomen World Method Create New Method Name  flipsHat Modify your object

Add Method Instructions

Calling a Method New Method must be “Called” Program Instructions must indicate to Execute the new Method In Alice Drag Method into World.MyFirstMethod In Other Languages Call the Method using Method Name The program starts running with the MyFirstMethod code.

Parameters Allows communication with Methods Communicate Values (Numbers, Colors) Communicate Object Names

Create Method with Parameter Create Method called “dance” Object will jump up and down and spin around Create Parameters Parameter 1 Which object to dance Parameter 2 How many times to Spin

Creating Parameter Which object to Dance Name Type: Arbitrary Placeholder – holds place of the actual object the will be used in the method Type: Number Boolean (True/False) Object Other (Sound, Color, Etc.) 1st parameter  which object to Dance Name: snowperson Type: object

Parameter Parameters show in Upper Left of Method Panel When Method is Called (Used) Object must be sent as an Argument to Method

Use Parameter in Method Drag the parameter into the method code section (as you would any other object)

Calling Method with Parameter When using Method you must include Parameter Use dance method after flipHat Example 1: Requires an object to dance Put after flipsHat – Use with Snowman and Snowwoman

Multiple Parameters Add Second Parameter – How many times to Spin Name: numberToSpin Type: Number Use in the Turn Instruction

Modify Method Call Change 2nd Parameter Pick any 2 different numbers Run the program using the method with parameters.

Create Another Method Create a Method for Snowman Blinking His Eyes Is this a World / Global Method Is this a Class Method Why How is it Created?

Homework Chapter 4, Section 1 (4-1) Chapter 4, Section 2 (4-2) #3 – Gallop and Jump #4 – Helicopter Flight Chapter 4, Section 2 (4-2) #6 – Frog Escape Bring electronic copy of homework to class Bring printed copy of homework to submit

Class Methods Class Methods are methods that define a behavior for one single class object. Select Horse Object Methods Create New Method gallop

Guidelines for Class Methods Create lots of class methods as necessary Do not call world-level methods from within a class-level method Do not use instructions for other objects from within a class-level method You can use parameters to send necessary information instead of referring to other specific objects from within the method. Create lots of class methods, they are useful and helpful  code reuse Do not call world-level methods  you may use an object of this class in another world that does not have this world-level method (error) Class-level methods should only refer to objects of the class that the method was created for. You may use this objects of this class and this class-level methods in other worlds and other programs that do not have these other objects.

Inheritance Creating a class on a previously defined class Adding functionality to existing class by defining new methods or editing existing ones Different members of design team can work on different methods for the class

Creating a New Class in ALICE Save object with new class methods as a New Class Code Reuse Galloping Horse 2 Step Process Rename existing object in Object Tree Save As a New Class

Rename Object Select the Object in the Object Tree Right-Click Rename Select a New Meaningful Name for Object GallopingHorse

Save As New Class Select the Object in the Object Tree Right-Click Save Object Navigate to folder where you want to save the object Other objects: Alice\Alice\Required\Gallery .a2c extension  Alice 2.0 class

New Class New Class (GallopingHorse) is now available in Object Gallery All objects of GallopingHorse all methods of horse class-method gallop

Homework Exercise 4-3 #10 #11  use a say instruction not a sound file so all worlds don’t have to import sound file Bring electronic copy of homework to class Bring printed copy of homework to submit