Class-level Methods and Inheritance .


20 views
Uploaded on:
Category: Funny / Jokes
Description
Class-level Methods and Inheritance. MMP 220 Multimedia Programming.
Transcripts
Slide 1

Class-level Methods and Inheritance MMP 220 Multimedia Programming The material in this freebee is taken from "Figuring out how to Program with Alice" a venture bolstered by the National Science Foundation under Grant NSF-0126833, NSF-0302542, and NSF-0339734. Contact Wanda Dann: wpdann@ithaca.edu, Stephen Cooper: scooper@sju.edu, Randy Pausch: pausch@cmu.edu, and Don Slater: dslater@cmu.edu http://www.aliceprogramming.net/This adjusted material was set up for understudies in MMP220 as a feature of an educational programs upgrade extend supported by National Science Foundation give #0511209 Co PI\'s Christopher Stein and Jody Culkin BMCC CUNY http://teachingmultimedia.net

Slide 2

Class-level Methods Some activities are actually connected with a particular class of items. Cases A man strolling A wheel moving We can compose our own strategies to characterize an activity for a particular class of articles - a class-level strategy.

Slide 3

An illustration (building strategy) How would we be able to make a skate technique for ice skater objects? We have to: advise Alice to relate the new technique (the one we are going to compose) with an ice skater, and compose another strategy to vitalize the ice skater skating.

Slide 4

Demo: The arrangement First, to relate the liveliness with the ice skater select the iceSkater tile in the Object Tree select the strategies tab in the subtle elements board tap on the make new strategy catch

Slide 5

Storyboard for Skate: Do together propel skater 2 meters Do all together slide on left leg slide on right leg The slide activities each require a few movement guidelines, so we will separate these two activities into littler strides

Slide 6

Stepwise Refinement of slideLeft Do all together Lift right leg and turn abdominal area forward Lower right leg and return body upright Skate: Do together 1) advance 2 meters 2) Do all together slideLeft slideRight Refinement of slideRight Do all together Lift left leg and turn abdominal area forward Lower left leg and return body upright

Slide 7

Demo Ch04Lec3Skater Concepts outlined in this illustration world A technique characterized for a particular sort of protest characterizes an activity for that question. A strategy can call different techniques. In this illustration, the skate strategy calls slideRight and slideLeft .

Slide 8

Reuse Writing techniques to make an ice skater play out a skating movement is a complicated errand. We might want to have the iceSkater skate in different universes without writing the strategies once more. Being ready to utilize beforehand composed program code in another program is known as reuse .

Slide 9

another class 1) Rename iceSkater as cleverSkater . 2) Save out as another class. Alice spares the new class as CleverSkater.a2c

Slide 10

Inheritance The CleverSkater class acquires every one of the properties and techniques from the first IceSkater class, furthermore has the recently characterized strategies ( skate, slideLeft, slideRight ) In other programming dialects, the idea of making another class in light of a formerly characterized class is called legacy .

Slide 11

Importing CleverSkater A case of the CleverSkater class can be added to another world – utilize File|Import .

Slide 12

Guidelines To keep away from potential abuse of class-level techniques, take after these rules: Avoid references to different articles Avoid calls to world-level strategies Play a sound just if the sound has been foreign made and spared out as a major aspect of the new class If these rules are not took after and an occurrence of the new class is added to a different universe, Alice will open an Error discourse box to let you know something isn\'t right.

Slide 13

Bad Example What if there is no penguin in the new world where a cleverSkater protest is foreign made?

Slide 14

Problem Suppose you truly need to compose a class-level strategy where another question is included? For instance, a technique to make the skater skate around another question - in this scene, the penguin.

Slide 15

Parameter An answer is to compose a class-level technique with a protest parameter that permits you to go in the particular question. cleverSkater.skateAround Parameter: whichObject Do all together Do together cleverSkater swing to confront whichObject cleverSkater lift right leg cleverSkater move to whichObject cleverSkater pivot whichObject

Slide 16

Translation to Code Most of the skateAround storyboard outline is direct and simple to code. One stage, in any case, requires some idea: cleverSkater move to whichObject - what separation ought to the cleverSkater move?

Slide 17

Calling an inherent capacity The direction to move the skater to whichObject (penguin, in this case) would resemble this: Unfortunately, the skater will slam into the penguin in light of the fact that the separation between two articles is measured focus to-focus.

Slide 18

Expression To dodge an impact, utilize a math administrator to make an expression that modifies the separation. Math administrators in Alice: expansion + subtraction  duplication * division/Example:

Slide 19

Demo Ch04Lec3SkateAround Concepts delineated: A parameter goes about as a placeholder for the question that will be passed in A call to the separation to capacity gives back a number esteem A math expression can be made as a component of a direction

Slide 20

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

Recommended
View more...