Objects and Object-Oriented Programming - PowerPoint PPT Presentation

About This Presentation
Title:

Objects and Object-Oriented Programming

Description:

Bunny, Bunny1, Bunny2. has color(s) Pink, White, Grey, Black, ... Bunny.turn(left, 0.5, ...) Motion Distance. Translational Distance ... Bunny.move(left, 1, ... – PowerPoint PPT presentation

Number of Views:112
Avg rating:3.0/5.0
Slides: 14
Provided by: wand91
Category:

less

Transcript and Presenter's Notes

Title: Objects and Object-Oriented Programming


1
Objects and
Object-Oriented Programming
  • CS 110 Honors
  • Slides by Wanda Dann, Ithaca College

2
Objects
  • What is an object ?
  • any thing that can be identified as unique from
    other things
  • How is an object identified as unique?
  • has a name
  • has properties
  • width, height, color, location, age, ss, id
  • has a purpose
  • associated actions it can perform
  • tasks it can carry out

3
Class
  • Objects are categorized into classes
  • Each object is
  • an instance of the class.
  • All objects in a class have similar properties
    and generally can perform the same tasks.

4
Objects in a Virtual World
  • In Alice, each 3-D model is an object
  • has a unique name
  • Bunny, Bunny1, Bunny2
  • has color(s)
  • Pink, White, Grey, Black, Blue, .
  • has 3 dimensions
  • height, width, depth

5
Object Orientation
  • Each object has 6 degrees of orientation
  • front, back, left, right, up, down
  • Orientation is relative to the object itself
  • Bunny.move(left, 1, )
  • is a move to the Bunny's left
  • But, an object is aware of its orientation
    relative to other objects
  • Bunny.pointAt(Helicopter)

6
3-D Space
  • An object is located in 3-D space

y
(0,0,0)
x
x is left - right y is up - down z is front -
back
z
7
Repositioning
  • Movement of an object changes its position in
    space.
  • Some movements are translational
  • Bunny.move(back, 0.5, )
  • Other movements are rotational
  • Bunny.turn(left, 0.5, )

8
Motion Distance
  • Translational Distance
  • 1 unit is about 1 meter (relative to the Virtual
    World dimensions)
  • Rotational Distance
  • 1 unit is 1 rotation (360 degrees -- full turn)
  • Can specify
  • fractional parts of a unit
  • 1/2
  • 0.5
  • multiple units
  • 2

9
Instructions
  • An instruction such as
  • Bunny.move(left, 1, )
  • is a statement that asks an object to perform
    an action or carry out a task.
  • Instructions must follow certain rules of syntax
  • objectName.actionName(argumentList)
  • Note
  • Instructions may have 0, 1, 2, or more
    arguments
  • Some arguments are optional, some are required

10
Time
  • Animation takes time -- even on fancy computers!
  • By default, executing an instruction in Alice
    takes 1 unit of time (approx. 1 second)
  • You can specify the amount of time
  • Bunny.move(left, 1, duration 2)
  • Note This instruction would slow down the move
    -- how could you speed it up?

11
Object Parts
  • Many objects are made up of parts (we say they
    are composites)
  • A part of an object moves
  • with the entire object, by default
  • on its own, if given a specific instruction
  • Bunny.head.leftear.turn(down, 1/8)
  • Syntax
  • objectName.partNameList.actionName(argumentList)

12
Object-Oriented Programming
  • An Alice program is
  • a scene containing
  • stationary objects -- like props on a stage
  • active objects -- will move around the scene
  • a list of instructions that ask the objects to
    perform tasks in the virtual world
  • So, an Alice program is object-oriented.

13
Reading and Lab
  • See handouts.
  • Note Lab exercises and projects require that
    you show me the code and execution of the
    programs created. I must "initial" your lab
    sheet for the exercises and projects or you will
    not get credit for them!
Write a Comment
User Comments (0)
About PowerShow.com