Upload
jordan-francis-parsons
View
216
Download
2
Tags:
Embed Size (px)
Citation preview
COSC 235: Programming and Problem Solving
Ch. 4 or… Everything is an ObjectInstructor: Dr. X
Goals
• Understand about objects as computational entities
• Understand and use methods and instance variables
• Use the dot notation• Use the graphics library
Everything is an Object
https://necessaryagitation.files.wordpress.com/2010/04/objects.gif
Everything is an Object
• Objects know stuff• Objects can do stuff• They are not exactly the same as the objects
that surround us• They are… computational entities!• Object Oriented (OO) Programming
Let’s code some objects
• Graphics: create some basic objects and get familiar with the graphics.py library
• We will use the “type” function to figure out what is going on
What did we learn?
• What did the type function reveal?• Where did we see a class before?• What is the difference between a method and
a function?• What is the difference between an instance
variable and a variable?
Everything is an Object
• Objects know stuff – instance variables• Objects can do stuff - methods
Class
• Determines the methods an object will have• An object is an instance of a class
Class vs Object
http://www.dgp.toronto.edu/~meng/courses/108/teaching99/lecture/3week/instance_variable.jpg
Instance Variable
http://www.dgp.toronto.edu/~meng/courses/108/teaching99/lecture/3week/instance_variable.jpg
Method
getName() getName()setName()setName()
Constructor
• A “special” method<class-name>(<param1>, <param2>, …)
• It builds objects
http://www.mymoneysocks.com/wp-content/uploads/2015/01/under_construction.jpeg
Let’s create some clones
Aliasing vs Cloning
• Alias: two variables refer to the same object• Clone: method that makes a copy of an object
Graphing Populations
• We will create a similar program as in the book but for populations
• NEED TO WORK ON EXAMPLE!!!
Event driven programming
• Event ~ Trigger• Event: Object that encapsulates data about
what just happened• Can you thing of example apps that are event
driven?
Event driven program
• Modify the convert.py to convert_gui.py• Add the option to convert meters to feet!