Presentation is loading. Please wait.

Presentation is loading. Please wait.

Fall 2007ACS-1805 Ron McFadyen1 Chapter 4 OO Programming Concepts.

Similar presentations


Presentation on theme: "Fall 2007ACS-1805 Ron McFadyen1 Chapter 4 OO Programming Concepts."— Presentation transcript:

1 Fall 2007ACS-1805 Ron McFadyen1 Chapter 4 OO Programming Concepts

2 Fall 2007ACS-1805 Ron McFadyen2 Elements of Programs Chapter 4 introduces more advanced OO programming techniques. Construction of a programs usually requires: Classes Objects Methods World-level Class-level Parameters Inheritance

3 Fall 2007ACS-1805 Ron McFadyen3 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)

4 Fall 2007ACS-1805 Ron McFadyen4 Classes Alice worlds are populated by selecting objects from a gallery of classes

5 Fall 2007ACS-1805 Ron McFadyen5 Classes Each class has properties, methods, functions We can customize by creating new properties, methods, functions

6 Fall 2007ACS-1805 Ron McFadyen6 Objects We instantiate objects when we “add objects” from the gallery

7 Fall 2007ACS-1805 Ron McFadyen7 Objects We instantiate objects when we “add objects” from the gallery

8 Fall 2007ACS-1805 Ron McFadyen8 Objects Showing the relationship amongst classes and objects: Teacher teacher2teacher1 Student student2student1student2

9 Fall 2007ACS-1805 Ron McFadyen9 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 a 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

10 Fall 2007ACS-1805 Ron McFadyen10 World-level Methods Instead of one complex method, we can break up a large complex task into smaller simpler ones. 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

11 Fall 2007ACS-1805 Ron McFadyen11 World-level Methods Original: Code is placed in a new method:

12 Fall 2007ACS-1805 Ron McFadyen12 World-level Methods Original:Revised: Original is long and complex The revised version is easily understood Note how a method is called Note use of comments

13 Fall 2007ACS-1805 Ron McFadyen13 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

14 Fall 2007ACS-1805 Ron McFadyen14 Parameters A method with a parameter: Some original code:

15 Fall 2007ACS-1805 Ron McFadyen15 Parameters Revised: Original: parameters What different kinds of parameters does Alice allow?

16 Fall 2007ACS-1805 Ron McFadyen16 Class-level Methods Any object can be extended to include new methods of your choosing e.g. your people object can be specialized to include a walk method.

17 Fall 2007ACS-1805 Ron McFadyen17 Class-level Methods After customizing an object you can save the object to a class from which you can instantiate (as from the gallery). If you customize alienRobot to include its own walk method and save it as a class named myRobot, then it has all the original properties, methods, functions of alienRobot and any new ones you define. We say that myRobot inherits the properties, methods, functions of alienRobot

18 Fall 2007ACS-1805 Ron McFadyen18 Class-level Methods An object can be saved as a class … and later on imported to instantiate an object in another world An object instantiated from myRobot inherits the properties, methods, functions of myRobot

19 Fall 2007ACS-1805 Ron McFadyen19 Class-level Methods Recommendations: Use many class-level methods Examine Lion, He/She builders for class-level methods Avoid references to world methods from class-level methods Avoid direct references to objects from within a class- level method – use parameters instead

20 Fall 2007ACS-1805 Ron McFadyen20 Tips/Techniques Some properties of objects and world: opacity: The opacity of an object is a measure of how difficult or easy it is to see through an object.

21 Fall 2007ACS-1805 Ron McFadyen21 Tips/Techniques Some properties of objects and world: isShowing: This property is either true or false and determines, respectively, if the object is visible or invisible. Whenever you add an object to a world it is initially visible.

22 Fall 2007ACS-1805 Ron McFadyen22 Rotating Objects Example Consider two objects that are to move, circling each other. Similar to the text example, commanding each to turn as seen by the other results in an odd result. But commanding each to turn about some invisible object does work. See demo


Download ppt "Fall 2007ACS-1805 Ron McFadyen1 Chapter 4 OO Programming Concepts."

Similar presentations


Ads by Google