JF 2 5
JF 2 5
2-5
Declare Procedures
JF 2-5 Copyright © 2019, Oracle and/or its affiliates. All rights reserved. 3
Declare Procedures
Objectives
This lesson covers the following objectives:
• Describe when to implement procedural abstraction
• Demonstrate how to declare a procedure
• Identify and use procedural abstraction techniques to
simplify animation development
JF 2-5 Copyright © 2019, Oracle and/or its affiliates. All rights reserved. 4
Declare Procedures
Object Movement
• Professional animators begin their process by
developing a scenario—or story—that gives the
animation a purpose.
• Examples:
– A story representing a conflict and resolution.
– A lesson to teach a math concept.
– A process to simulate or demonstrate.
– A game to play for entertainment or training.
JF 2-5 Copyright © 2019, Oracle and/or its affiliates. All rights reserved. 5
Declare Procedures
Scenario and Animation Examples
Defining the scenario, and the animation to represent the
scenario, is the first step to programming your animation.
Scenario Type Scenario Animation
A cat needs help to get A firefighter climbs up the tree to
Story
down from a tree. save the cat.
JF 2-5 Copyright © 2019, Oracle and/or its affiliates. All rights reserved. 6
Declare Procedures
What is a Storyboard?
• A storyboard identifies the design specifications for the
animation scenario:
– How objects appear, move, speak, interact, and so on.
• Once a scenario is defined, you can begin to develop
the animation storyboard.
• Two types of storyboards are used to plan an
animation:
– Visual: A series of illustrated images that represent the main
scenes of the animation.
– Textual: A detailed, ordered list of actions that each object
performs in each scene of the animation.
JF 2-5 Copyright © 2019, Oracle and/or its affiliates. All rights reserved. 7
Declare Procedures
Storyboard Formats
Storyboards are created in the following formats:
• Drawn with paper and pencil.
• Created using digital tools such as a word processing
program, paint or drawing program, or presentation.
• Created using comments in the Alice 3 Code editor.
JF 2-5 Copyright © 2019, Oracle and/or its affiliates. All rights reserved. 8
Declare Procedures
Visual Storyboards
A visual storyboard helps the reader understand:
• The components of a scene.
• How the initial scene will be set-up.
• The moving and non-moving objects in a scene.
• The actions that will take place.
• The user interactions that will occur during the
animation execution.
JF 2-5 Copyright © 2019, Oracle and/or its affiliates. All rights reserved. 9
Declare Procedures
Visual Storyboard Example
Boy and girl sit on a Girl notices the mobile Girl says out loud
park bench. The boy phone. She thinks, "Hey! You forgot your
walks away, leaving "Hey! That boy forgot phone!" Boy turns
his phone behind. his phone!" around and walks
back to bench. He
says, "Oh! thank you!"
JF 2-5 Copyright © 2019, Oracle and/or its affiliates. All rights reserved. 10
Declare Procedures
Textual Storyboards
• A textual storyboard helps the reader understand the
actions that will take place during the animation.
• The moving and non-moving objects can be easily
identified within the action statements, but a more
detailed description may be necessary if additional
programmers are also involved in implementing any
scene.
An algorithm is a list of actions to perform a task or solve a problem.
In computing, a textual storyboard is an algorithm.
JF 2-5 Copyright © 2019, Oracle and/or its affiliates. All rights reserved. 11
Declare Procedures
Textual Storyboard Example 1
Program the following actions in order:
• Boy and girl sit on a park bench.
• Boy stands up and walks away, leaving his mobile phone on
the park bench.
• Girl turns to look at the phone.
• Girl thinks, "Hey! That boy forgot his phone!"
• Girl says out loud, "Hey! You forgot your phone!"
• Boy stops and turns around.
• Boy walks back to the park bench and says, "Oh! Thank
you!"
JF 2-5 Copyright © 2019, Oracle and/or its affiliates. All rights reserved. 12
Declare Procedures
Textual Storyboard Example 2
• This example shows how you can develop your
storyboard by first writing comments in the Code editor
of your program.
• Afterwards, you can start to develop the animation
directly from the storyboard.
JF 2-5 Copyright © 2019, Oracle and/or its affiliates. All rights reserved. 13
Declare Procedures
Textual Storyboard Components
Component Definition Examples
JF 2-5 Copyright © 2019, Oracle and/or its affiliates. All rights reserved. 14
Declare Procedures
Flowcharting a Storyboard
Flowcharting a storyboard helps you organize the flow of
the animation actions and conditions.
End
JF 2-5 Copyright © 2019, Oracle and/or its affiliates. All rights reserved. 15
Declare Procedures
Using Storyboards to Organize Your Program
• Textual storyboards can be used to generate program
comment statements and organize program
development.
• Storyboards can also help programmers identify
repetitive actions for one object, and identical actions
that may be performed by multiple objects.
JF 2-5 Copyright © 2019, Oracle and/or its affiliates. All rights reserved. 16
Declare Procedures
Inherited Characteristics
• Let's examine how a Dalmatian inherits its
characteristics:
• Characteristics of the Dog class (the parent class or
"superclass") include four legs, two eyes, fur, and the
ability to bark.
• Characteristics of the Dalmatian breed class (the child
class or "subclass," which is a subset of the dog class)
include white fur, black spots, and other characteristics.
Dog Class (Superclass)
Dalmatian Class
(Subclass)
JF 2-5 Copyright © 2019, Oracle and/or its affiliates. All rights reserved. 17
Declare Procedures
Class Inheritance
• Just like animals in the real world, objects in the
programming world inherit the characteristics of their
class, including all of the class's methods (procedures
and functions).
• For example, all objects within the quadruped class in
Alice inherit the quadruped characteristics of four legs,
a head, a body, etc.
• Within this quadruped superclass, subclasses exist for
dogs, cats, wolves, lions, cows, etc.
• Each subclass adds characteristics that more specifically
identify the objects within it.
JF 2-5 Copyright © 2019, Oracle and/or its affiliates. All rights reserved. 18
Declare Procedures
Identifying Repetitive Behaviors in Your
Storyboard
• Understanding that subclasses belong to superclasses
helps you, as a programmer, identify repetitive
behaviors in your storyboard.
• For example:
– If you plan to program a dog, cat, and lion to walk, you should
program the repetitive behavior of walking at the superclass, or
quadruped, level.
– The result is that all of the subclasses (dog, cat, lion) can use
the inherited characteristic of walking, and you do not have to
program the repetitive walking behavior for each object
individually.
JF 2-5 Copyright © 2019, Oracle and/or its affiliates. All rights reserved. 19
Declare Procedures
Inheritance
When a Dalmatian object is created, it inherits
procedures, functions, and properties from the
quadruped class and the Dalmatian subclass that you can
view in the Code editor.
JF 2-5 Copyright © 2019, Oracle and/or its affiliates. All rights reserved. 20
Declare Procedures
Create Inherited Methods
• In addition to the pre-defined methods, you can create
your own methods and have them display, or be
available for, any subclass object.
• Inherited methods will always display at the top of the
list of pre-defined methods once they are created.
JF 2-5 Copyright © 2019, Oracle and/or its affiliates. All rights reserved. 21
Declare Procedures
myFirstMethod Tab
The myFirstMethod tab is displayed by default when the
Code editor is opened.
JF 2-5 Copyright © 2019, Oracle and/or its affiliates. All rights reserved. 22
Declare Procedures
Class Hierarchy
Click the class hierarchy drop-down menu to the left of
the myFirstMethod tab (indicated by a down-pointing
arrow) to view the list of classes and subclasses in your
animation.
JF 2-5 Copyright © 2019, Oracle and/or its affiliates. All rights reserved. 23
Declare Procedures
View the Class Methods
Select a superclass or subclass to view the procedures,
functions, and properties defined for the selected class.
JF 2-5 Copyright © 2019, Oracle and/or its affiliates. All rights reserved. 24
Declare Procedures
Procedural Abstraction
• Review the existing code or the textual storyboard to
identify and plan the methods that you need to declare in
your program.
• Procedural abstraction may need to be implemented if an
object in Alice needs to perform an action, but there isn't
an inherited procedure that accomplishes that action.
• Identify a repetitive behavior and create one method for
it:
– Simplifies the code, making it easier to read.
– Allows many objects of a class to use the same method.
– Allows subclasses of a superclass to use the method.
JF 2-5 Copyright © 2019, Oracle and/or its affiliates. All rights reserved. 25
Declare Procedures
Procedural Abstraction Defined
• An example of procedural abstraction is the removal of
a repetitive or lengthy programming statement from
myFirstMethod and the placing of it into its own
method to make the code easier to read, understand,
and reuse by multiple objects and multiple classes.
JF 2-5 Copyright © 2019, Oracle and/or its affiliates. All rights reserved. 26
Declare Procedures
Procedural Abstraction Example 1
• One or more objects may perform the same repetitive
motions.
• The animating of one swimming fish requires the
writing of many repetitive procedures which must then
be repeated for each fish in the school,
taking up a lot of space
in myFirstMethod.
JF 2-5 Copyright © 2019, Oracle and/or its affiliates. All rights reserved. 27
Declare Procedures
Procedural Abstraction Example 2
• Sometimes, a procedure needed to perform an action is
not available by default.
• For example, a bird needs to fly, but a fly procedure is
not available for bird objects.
JF 2-5 Copyright © 2019, Oracle and/or its affiliates. All rights reserved. 28
Declare Procedures
When Procedural Abstraction Occurs
• Procedural abstraction can occur before or after
programming statements are created.
• However, by developing the storyboard first, the
programmer can more easily identify the procedures
that will be needed before the programming begins.
JF 2-5 Copyright © 2019, Oracle and/or its affiliates. All rights reserved. 29
Declare Procedures
Examples of When to Declare a Procedure
Declare a procedure when:
• Motions do not have a default procedure, such as a bird
flying.
• Motions need to be used by multiple objects or classes,
such as all quadrupeds hopping up and down.
• Singular motions require many programming
statements, such as a person moving body parts to
walk.
JF 2-5 Copyright © 2019, Oracle and/or its affiliates. All rights reserved. 30
Declare Procedures
Declaring a Procedure Example 1
• The bird flies by, turning its shoulders and moving
forward simultaneously.
• This repetitive motion can be extracted into its own
flying procedure.
Do together: Do together:
Bird turns right shoulder backward Bird flies
Bird turns left shoulder backward Bird moves forward
Bird moves forward
Do together:
Bird turns right shoulder forward
Bird turns left shoulder forward
Bird moves forward
JF 2-5 Copyright © 2019, Oracle and/or its affiliates. All rights reserved. 31
Declare Procedures
Declaring a Procedure Example 2
• Each bunny moves up and down in order to simulate a
hopping motion.
• This repetitive motion used by all bunny objects could
be extracted into its own hop procedure.
JF 2-5 Copyright © 2019, Oracle and/or its affiliates. All rights reserved. 32
Declare Procedures
Steps to Declare a Procedure
• From the class hierarchy, select the class that should
inherit the procedure.
• All subclasses will then inherit the procedure as well.
(These are indented underneath their superclass.)
• Click the Add Procedure... button.
JF 2-5 Copyright © 2019, Oracle and/or its affiliates. All rights reserved. 33
Declare Procedures
Steps to Declare a Procedure
• Specify a name for the procedure and then click OK.
• A new tab with the name of the procedure will open.
• Write the code for the procedure.
• Add the new procedure to myFirstMethod right away so
that when you test the animation in myFirstMethod,
you are also testing the animation in the new
procedure.
JF 2-5 Copyright © 2019, Oracle and/or its affiliates. All rights reserved. 34
Declare Procedures
Steps to Add Procedure to myFirstMethod
Tab Before Programming
• Click the myFirstMethod tab.
• Select the instance for which you are coding the
procedure from the instance menu.
• In the Procedures tab, locate the
declared procedure and drag it
into myFirstMethod.
JF 2-5 Copyright © 2019, Oracle and/or its affiliates. All rights reserved. 35
Declare Procedures
Steps to Add a Declared Procedure to Your
Code
• Select the instance of the object to which you wish to
add the declared procedure.
• Find the declared procedure listed under the
Procedures tab in the methods panel.
• The declared procedures
are available in the
procedures tab for all
objects that inherit them.
• Drag the declared
procedure to the code.
JF 2-5 Copyright © 2019, Oracle and/or its affiliates. All rights reserved. 36
Declare Procedures
Steps to Access and Edit Declared
Procedures
• In the instance menu, select the instance where the
procedure was declared.
• Click Edit to the left of the procedure name.
JF 2-5 Copyright © 2019, Oracle and/or its affiliates. All rights reserved. 37
Declare Procedures
Steps to Access and Edit Declared
Procedures
• Create or edit the programming instructions for the
procedure.
• Click the Run button to test the procedure and debug as
necessary.
• When finished editing the procedure, click the
myFirstMethod tab to return.
JF 2-5 Copyright © 2019, Oracle and/or its affiliates. All rights reserved. 38
Declare Procedures
Identify Opportunities for Declared
Procedures
• As you program, continually identify opportunities to
declare procedures using procedural abstraction
techniques.
• For example, in myFirstMethod, the fish bobs up and
down repeatedly.
• A separate "bob" procedure should be declared as a
result.
JF 2-5 Copyright © 2019, Oracle and/or its affiliates. All rights reserved. 39
Declare Procedures
Procedural Abstraction and Using the
Clipboard
• After you have written many programming instructions
in the myFirstMethod tab, you may determine that the
code would serve your program better if it were in a
declared procedure.
• To save time, you can drag the programming
instructions onto the clipboard icon.
• Then, after creating the declared procedure, you can
drag the programming instructions from the clipboard
into the declared procedure.
JF 2-5 Copyright © 2019, Oracle and/or its affiliates. All rights reserved. 40
Declare Procedures
Use Inherited Procedures
• Procedures declared at
the superclass level are
available to the other
objects in that class.
• For example, a
"bipedWave" procedure
created to make a
playingCard wave his arms
in the air could be used to
make Alice wave her arms
in the air as well.
JF 2-5 Copyright © 2019, Oracle and/or its affiliates. All rights reserved. 41
Declare Procedures
Declare Procedure at Superclass Level
• Declare the "bipedWave" procedure at the biped
superclass level so that the playingCards and Alice can
both use the procedure.
• Any other bipeds that may be added later would also
have access to this procedure.
JF 2-5 Copyright © 2019, Oracle and/or its affiliates. All rights reserved. 42
Declare Procedures
this Object Identifier
• When a declared procedure is created, the object
identifier, this, is used to indicate that the instance
calling the procedure is this.
JF 2-5 Copyright © 2019, Oracle and/or its affiliates. All rights reserved. 43
Declare Procedures
this Object Identifier Example
• If Alice is selected in the instance menu, then
the bipedWave procedure is added to myFirstMethod;
this in the declared procedure refers to Alice.
JF 2-5 Copyright © 2019, Oracle and/or its affiliates. All rights reserved. 45
Declare Procedures
Summary
In this lesson, you should have learned how to:
• Compare and define an animation and a scenario
• Write a storyboard
• Flowchart a storyboard
• Describe inheritance and how traits are passed from
superclasses to subclasses
JF 2-5 Copyright © 2019, Oracle and/or its affiliates. All rights reserved. 46
Declare Procedures
Summary
In this lesson, you should have learned how to:
• Describe when to implement procedural abstraction
• Demonstrate how to declare a procedure
• Identify and use procedural abstraction techniques to
simplify animation development
JF 2-5 Copyright © 2019, Oracle and/or its affiliates. All rights reserved. 47
Declare Procedures