1 / 13

Objects and Object-Oriented Programming

Objects and Object-Oriented Programming. CS 110 – Honors Slides by Wanda Dann, Ithaca College. 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:

mort
Download Presentation

Objects and Object-Oriented Programming

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  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. Peter Person Paul Mary Spike Dogs Scottie Fluffy Class • Objects are categorized into classes • Each object is an instance of the class. • All objects in a class have similar propertiesand 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!

More Related