1 / 8

CPSC 203 Tutorial

CPSC 203 Tutorial. Xin Liu Nov 24, 2010. Object-oriented programming. A mimic of real world The world is composed of objects An object has some properties and methods and functions Components of OOP Classes The types/templates of objects Objects The instances of classes

bela
Download Presentation

CPSC 203 Tutorial

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. CPSC 203 Tutorial Xin Liu Nov 24, 2010

  2. Object-oriented programming • A mimic of real world • The world is composed of objects • An object has some properties and methods and functions • Components of OOP • Classes • The types/templates of objects • Objects • The instances of classes • Different objects can be created from the same class • The objects share the same methods but can have different names and properties • Methods • A method is an action that an object can take, actually composed of a sequence of instructions.

  3. Exercise • Create two objects from the camel class, named as Camelo and Camely. Camelo has red ears; Camely has blue ears. Camelo is bigger; Camely is smaller.

  4. More on methods • Build-in methods • User-defined methods • Class-level methods • The actions of an object • E.g. Iceskater.roll and Bunny.hop • World-level methods • The actions involving more than one objects • E.g. World.Iceskater discusses with Snowman • World.my first method is the “main program” we used to work on

  5. Exercise • Go through Tutorial 2.

  6. Exercise • Download and open lab4ggypt.a2w • Create a class-level method on Pharaoh, getScared • Beard enlarged by 1.2; nose enlarged by1.2; hat turns 1 rev; says “Aaaaah!” • Create a world-level method, getScared • Camera focuses on the Pharaoh • Show the mummy scared • Call world.getScared from world.myFirstMethod

  7. Exercise • Add a class-level method, getScared, to Mummy • Head grows by 1.2 and then shrinks by 1/1.2; yells “Oooooh!” at the same time. • Edit the world-level method, getScared • Focus the camera to the mummy • Call mummy.getScared • Add a dummy object at the camera’s original position • Edit the world-level method, getScared • Turn the camera back

  8. Summary • Two class-level methods • One world-level method • A neat program is obtained by splitting the code into class and world-level methods

More Related