Download presentation
Presentation is loading. Please wait.
Published byDayna Ray Modified over 9 years ago
1
OOP and Graphics
2
Object Oriented Programming The ‘classic’ point of view of a programmer was that the program instructions were the active part, the data just sat there and was manipulated. A new paradigm became popular in the 80’s: OOP The idea is that programs should be considered as interactions of objects. An object was a structure that “knew things” (i.e. had data values) and “did things” (i.e. had operations to do on the data) (There’s quite a bit more to the paradigm than that, but that will do for now.)
3
Objects in Graphics The graphics library is set up as a collection of object templates Point, Circle, Rectangle, Line and so on These templates are called “classes”. They are the “pattern” for what a particular object should be. Example: a Point class would have data about the position of the point (x, y) and functions that could do things with that information You call a function called a “constructor” to make a new object from the class. Constructor methods are almost always the same name as the name of the class. (Objects are also called “instances”.)
4
Objects in Graphics Once you have an object constructed, it has a name. You can give the object commands by calling the methods (functions) that it knows about. Example: p = Point(200, 300) # p is now an object from class Point p.draw(win) p.move(0, 5) Note the syntax: “dot notation”. The statement or expression starts with the object name, followed by a dot, then the name of the method and its arguments, if any.
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.