1
1
Aaron Stevens
11 February 2009
CS108 Lecture 11: Objects and Graphics
Objects and Classes Graphics Concepts
2
Review/Questions What are objects, and how do they help us program - - PDF document
CS108 Lecture 11: Objects and Graphics Objects and Classes Graphics Concepts Aaron Stevens 11 February 2009 1 Review/Questions What are objects, and how do they help us program more effectively? Constructors: How to create
1
2
3
An analogy using cars: Consider a 2002 Honda Civic LX 4-door 5-speed, green exterior, grey interior, with AC. What does this describe, really? Can you drive it? What kind of condition is it in?
– This actually describes an engineering specification from which an entire class of identical cars could be created.
Now consider my wife’s car… what is it, really?
– This describes a single instance of a vehicle -- made to the specification
4
5
6
7
p.draw(win)
8
<object>.<method-name>(<param1>, <param2>,…)
>>> circ.draw(win) >>> circ.setFill("green") >>> circ.move(10,10)
9
10
>>> p.getX() >>> p.getY() >>> circ.undraw()
11
12
13
Recall the python string module we used last week? Turns out, string is an object in Python; we can use <object>.<method> notation to call up its methods. Examples: s = “hello, world” s.upper() s.find(‘ ‘)
14
15
16
17