1 / 17

CISC 110 Day 4

CISC 110 Day 4. Object-oriented Programming (OOP). Outline. Typecasting (continued from last day) Introduction to OOP Classes Setting properties Using methods Applying methods to Objects Parameters to provide options. Typecasting.

kohana
Download Presentation

CISC 110 Day 4

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. CISC 110Day 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

  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

  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 instanceof 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 is a is a is a SanDisk Sansa Fuze Class iPod nano Class Microsoft Zune Class … … … Sansa Fuze object instances iPod nano object instances Zune object instances 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 Instanceswith a Constructor Method Example: var myCircle: MovieClip; // Creates a variable of type MovieClip myCircle = new MovieClip( ); // Creates an instance of MovieClip General Syntax: var <variable name> : <class>; <variable name> = new <class> ( ); 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 ); Parametersprovide options, so a method can do variations of an operation, not always the same thing. 17

More Related