1 / 19

Methods

Methods. Alice May 30, 2012. Larger Programs. As you become more skilled in writing programs, you will find that programs quickly increase to many, many lines of code. Games and other "real world" software applications can have thousands, even millions of lines of code. Potential Problem.

bendek
Download Presentation

Methods

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. Methods Alice May 30, 2012

  2. Larger Programs • As you become more skilled in writing programs, you will find that programs quickly increase to many, many lines of code. • Games and other "real world" software applications can have thousands, even millions of lines of code.

  3. Potential Problem • The program code just seemed to grow and grow. • If we continue to write programs this way the programs will become longer and more difficult to read and think about.

  4. Methods • Object-oriented programming uses classes, objects, and methods as basic programming components. • These components help to • organize a large program into small modules • design and think about an intricate program • find and remove errors (bugs)

  5. Why? • Why do we want to write our own methods? • saves time -- we can call the method again and again without reconstructing code • reduces code size – we call the method rather than writing the instructions again and again • allows us to "think at a higher level" • can think surprise instead of “The alien moves up and says ‘Slithy toves?’ and then the robot's head turns around. " • the technical term for "think at a higher level" is "abstraction"

  6. We can use… • built-in (predefined) methods • Examples: move, turn to face, say • your own method (you created the method) • Examples: Spin, Wink, Skate

  7. Ice Skater spin method example

  8. Demo: Starting a new method • First, to associate the new method with the World • select the World tile in the Object Tree • select the methods tab in the details area • click on the "create new method" button

  9. How to write a Method: • Steps to writing Methods • create them • call them

  10. Today’s Program • Open Alice • Create your skater program.

  11. Let’s create our coding

  12. Create new method:

  13. That’s it! • Play your program – does it work. • Press W and space bar. • Does your skater spin and wink?

More Related