Presentation is loading. Please wait.

Presentation is loading. Please wait.

Fall 2008ACS-1805 Ron McFadyen1 Programming Concepts Chapter 4 introduces more advanced OO programming techniques. Construction of a programs usually requires:

Similar presentations


Presentation on theme: "Fall 2008ACS-1805 Ron McFadyen1 Programming Concepts Chapter 4 introduces more advanced OO programming techniques. Construction of a programs usually requires:"— Presentation transcript:

1 Fall 2008ACS-1805 Ron McFadyen1 Programming Concepts Chapter 4 introduces more advanced OO programming techniques. Construction of a programs usually requires: Classes Objects Methods World-level Class-level Parameters Inheritance

2 Fall 2008ACS-1805 Ron McFadyen2 Classes An OO program is organized around the concept of class. For Alice programming, all classes are pre-defined for us. We choose the classes our program requires from the gallery. We need other skills to build classes If interested, you would want to learn about products such as Maya, Max Studio, … These products are used to construct 3D models Constructing or building classes is outside the scope of this course Two things that distinguish classes: Classes are defined to have properties and methods (including functions)

3 Fall 2008ACS-1805 Ron McFadyen3 Classes Each class has properties, methods, functions We can customize by creating new properties, methods, functions

4 Fall 2008ACS-1805 Ron McFadyen4 Objects Showing the relationship amongst classes and objects: Teacher teacher2teacher1 Student student2student1student2

5 Fall 2008ACS-1805 Ron McFadyen5 Methods Each class/object has a collection of methods that define the things an object from that class can do Move, Turn, Roll, etc We can’t see the code comprising these. (The Alice creators don’t want us to change them and they are referred to as primitive methods We can customize an object by giving it some new methods you are able to edit those OO programmers typically use many many methods where each is defined to some fairly simple thing Methods give us a way of organizing the complexity of our creations Methods become even more useful when they incorporate parameters

6 Fall 2008ACS-1805 Ron McFadyen6 World-level Methods If we have a complex method, we can break it up into smaller simpler tasks. The main idea is to take a group of related instructions in one method, place them in a separate method, and replace the original lines with a call to the new method The principle we are applying is called abstraction – we are now thinking of the group of instructions as a single instruction

7 Fall 2008ACS-1805 Ron McFadyen7 Stepwise refinement When creating an algorithm we can design a solution in terms of solutions to smaller problems. This approach is one where we divide and conquer - we break a task down into a number of sub-tasks, each of which is described by an algorithm that is smaller and simpler than that for the entire process. Each sub-task may require further sub-division until we have divided up the problem into elementary pieces, each of which can be tackled in a simple and straightforward way.

8 Fall 2008ACS-1805 Ron McFadyen8 World-level Methods Original: Code is placed in a new method:

9 Fall 2008ACS-1805 Ron McFadyen9 World-level Methods Original:Revised: Original is long and complex The revised version is easily understood Note how a method is called

10 Fall 2008ACS-1805 Ron McFadyen10 Parameters A method is more useful if it can work for different objects A robot walks by turning a leg part backward and then forward We can place these two turns into a method with a parameter – where the parameter is used to specify the part involved

11 Fall 2008ACS-1805 Ron McFadyen11 Parameters A method with a parameter: Some original code:

12 Fall 2008ACS-1805 Ron McFadyen12 Parameters Revised: Original: parameters What different kinds of parameters does Alice allow?

13 Fall 2008ACS-1805 Ron McFadyen13 Consider Project 4, Cleanup Robot We are told to use 3 methods… to make it easier to understand a solution… to make it easier to develop the solution Put Toys Away (storyboard) For each toy: pickup- robot goes and picks up the toy putInCloset- robot takes the toy to the closet Example solution is given in terms of solutions to 2 smaller problems

14 Fall 2008ACS-1805 Ron McFadyen14 Example pickup- robot goes and picks up the toy Robot turns to face the toy Robot moves toward the toy Robot picks up toy putInCloset- robot takes the toy to the closet Robot turns to face the closet Closet door opens Robot moves into the closet putdown- robot places toy in closet Robot exits from the closet Closet door closes putdown- robot places toy in closet Robot lowers his arms Robot releases the toy Parameters object; distance to move object

15 Fall 2008ACS-1805 Ron McFadyen15 Example Put toys away pickupputInCloset putdown We can represent the overall organization of our methods (who calls who)


Download ppt "Fall 2008ACS-1805 Ron McFadyen1 Programming Concepts Chapter 4 introduces more advanced OO programming techniques. Construction of a programs usually requires:"

Similar presentations


Ads by Google