Programming Concepts - PowerPoint PPT Presentation

1 / 15
About This Presentation
Title:

Programming Concepts

Description:

Chapter 4 introduces more advanced OO programming techniques. ... We choose the classes our program requires from the gallery. ... – PowerPoint PPT presentation

Number of Views:67
Avg rating:3.0/5.0
Slides: 16
Provided by: wand85
Category:

less

Transcript and Presenter's Notes

Title: Programming Concepts


1
Programming Concepts
  • Chapter 4 introduces more advanced OO programming
    techniques.
  • Construction of a programs usually requires
  • Classes
  • Objects
  • Methods
  • World-level
  • Class-level
  • Parameters
  • Inheritance

2
Classes
  • An OO program is organized around the concept of
    class.
  • For Alice programming, all classes are
    pre-defined for us.
  • We choose the classes our program requires from
    the gallery.
  • We need other skills to build classes
  • If interested, you would want to learn about
    products such as Maya, Max Studio,
  • These products are used to construct 3D models
  • Constructing or building classes is outside the
    scope of this course
  • Two things that distinguish classes
  • Classes are defined to have properties and
    methods (including functions)

3
Classes
  • Each class has properties, methods, functions
  • We can customize by creating new properties,
    methods, functions

4
Objects
  • Showing the relationship amongst classes and
    objects

Student
Teacher
student2
student1
student2
teacher2
teacher1
5
Methods
  • Each class/object has a collection of methods
    that define the things an object from that class
    can do
  • Move, Turn, Roll, etc
  • We cant see the code comprising these. (The
    Alice creators dont want us to change them and
    they are referred to as primitive methods
  • We can customize an object by giving it some new
    methods
  • you are able to edit those
  • OO programmers typically use many many methods
    where each is defined to some fairly simple thing
  • Methods give us a way of organizing the
    complexity of our creations
  • Methods become even more useful when they
    incorporate parameters

6
World-level Methods
  • If we have a complex method, we can break it up
    into smaller simpler tasks.
  • The main idea is to take a group of related
    instructions in one method, place them in a
    separate method, and replace the original lines
    with a call to the new method
  • The principle we are applying is called
    abstraction we are now thinking of the group of
    instructions as a single instruction

7
Stepwise refinement
  • When creating an algorithm we can design a
    solution in terms of solutions to smaller
    problems. This approach is one where we divide
    and conquer - we break a task down into a number
    of sub-tasks, each of which is described by an
    algorithm that is smaller and simpler than that
    for the entire process.
  • Each sub-task may require further sub-division
    until we have divided up the problem into
    elementary pieces, each of which can be tackled
    in a simple and straightforward way.

8
World-level Methods (4-1)
  • Original

Code is placed in a new method
9
World-level Methods
  • Original

Revised
  • Original is long and complex
  • The revised version is easily understood
  • Note how a method is called

10
Parameters (4-2)
  • A method is more useful if it can work for
    different objects
  • A robot walks by turning a leg part backward and
    then forward
  • We can place these two turns into a method with a
    parameter where the parameter is used to
    specify the part involved

11
Parameters
  • Some original code
  • A method with a parameter

12
Parameters
  • Original

What different kinds of parameters does Alice
allow?
  • Revised

parameters
13
Example
  • Consider Project 4, Cleanup Robot, page 117
  • We are told to use 3 methods to make it easier
    to understand a solution to make it easier to
    develop the solution
  • Put Toys Away (storyboard)
  • For each toy
  • pickup- robot goes and picks up the toy
  • putInCloset- robot takes the toy to the closet

solution is given in terms of solutions to 2
smaller problems
14
Example
Parameters
pickup- robot goes and picks up the toy Robot
turns to face the toy Robot moves toward the
toy Robot picks up toy putInCloset- robot takes
the toy to the closet Robot turns to face the
closet Closet door opens Robot moves into the
closet putdown- robot places toy in closet Robot
exits from the closet Closet door
closes putdown- robot places toy in closet Robot
lowers his arms Robot releases the toy
object distance to move
object distance to move
object
15
Example
We can represent the overall organization of our
methods (who calls who)
Put toys away
pickup
putInCloset
putdown
Write a Comment
User Comments (0)
About PowerShow.com