Presentation is loading. Please wait.

Presentation is loading. Please wait.

CISC 110 Day 4 Object-oriented Programming (OOP).

Similar presentations


Presentation on theme: "CISC 110 Day 4 Object-oriented Programming (OOP)."— Presentation transcript:

1 CISC 110 Day 4 Object-oriented Programming (OOP)

2 Outline Typecasting (continued from last day) Introduction to OOP Classes Setting properties Using methods Applying methods to Objects Parameters to provide options 2

3 Typecasting Typecasting is the process of converting a value of one data type into a value of another data type. Example: var i:int = 100; var s:String = String(i); trace(s); Output: 100 3

4 Object-oriented Programming Object-oriented Programming (OOP) is a programming paradigm that uses variables called objects to manipulate other objects. Related Terms: -Information hiding -Data abstraction -Encapsulation -Modularity -Polymorphism -Inheritance 4

5 Library System Example Tasks: Borrow a book Return a book Search book lists by title, author or subject Issue new library card Check library card for books borrowed Obtain address of library card owner Add a new book to library Remove an old book Add a new employee to library staff Remove an employee (they’ve left for a job in computing science) 5

6 Library System Example Main Objects: Book Borrow Return Add new book Remove old book Search book list Employee Add a new employee to library staff Remove an employee Card Holder Issue new card Check for books borrowed Obtain address 6

7 OO Terminology Objects: Data items manipulated by a computer program e.g. an MP3 Player Methods: Operations performed by (or on) an object e.g. pause Attributes: Characteristics that describe the state of an object (properties) e.g. the song now playing 7

8 OO Terminology Class –A template that describes the methods and attributes of a group of objects e.g. description of iPod nanos –The group of all objects that fit that description, each of which is an instance of the class e.g. the group of all the 321,520,001 iPod nanos in the world 8

9 Hierarchy of Classes Generic MP3 Player Class Microsoft Zune Class iPod nano Class SanDisk Sansa Fuze Class ……… Sansa Fuze object instancesiPod nano object instancesZune object instances is a An iPod “is a” MP3 Player 9

10 OO Terminology Inheritance: A subclass can “inherit” the characteristics and capabilities of a class above it in the hierarchy without redefining them, so that their common properties only need to be defined once. e.g. Generic CD class common methods: ‘play’,‘pause’, etc. e.g. Sansa Fuze extra method: ‘shuffle’ 10

11 Creating Object Instances with a Constructor Method Example: var myCircle: MovieClip;// Creates a variable of type MovieClip myCircle = new MovieClip( );// Creates an instance of MovieClip General Syntax: var : ; = new ( ); 11

12 Constructor Methods Every class for creating objects has a constructor method. The constructor method sets the initial values of the attributes of the new object. 12

13 Some MovieClip Properties width height x y Width of a MovieClip Height of a MovieClip x-coordinate position of a MovieClip y-coordinate position of a MovieClip 13

14 Some MovieClip Methods play() stop() nextFrame() goToAndPlay(x) goToAndStop(x) Tells playhead to play a MovieClip’s timeline from its current frame location Tells playhead to stop at a frame in a MovieClip’s timeline Tells playhead to advance to the next frame and stop in a MovieClip’s timeline Tells MovieClip to move the playhead and play from a specific frame on its timeline Tells MovieClip to move the playhead and stop at a specific frame on its timeline 14

15 Syntax for Setting a Property myCircle.height = 20; semi-colon object’s property assignment property variable name operator (=) value name period 15

16 Syntax for Calling a Method myCircle.play( ); semi-colon object’s method parentheses variable name (may be parameters) name period 16

17 Setting Attributes and Using Methods Examples: myCircle.x = 40; parameter myCircle.height = 30; myCircle.goToAndPlay( 10 ); Parameters provide options, so a method can do variations of an operation, not always the same thing. 17


Download ppt "CISC 110 Day 4 Object-oriented Programming (OOP)."

Similar presentations


Ads by Google