+ All Categories
Home > Documents > COSC 235: Programming and Problem Solving Ch. 4 or… Everything is an Object Instructor: Dr. X.

COSC 235: Programming and Problem Solving Ch. 4 or… Everything is an Object Instructor: Dr. X.

Date post: 04-Jan-2016
Category:
Upload: jordan-francis-parsons
View: 215 times
Download: 2 times
Share this document with a friend
Popular Tags:
17
COSC 235: Programming and Problem Solving Ch. 4 or… Everything is an Object Instructor: Dr. X
Transcript
Page 1: COSC 235: Programming and Problem Solving Ch. 4 or… Everything is an Object Instructor: Dr. X.

COSC 235: Programming and Problem Solving

Ch. 4 or… Everything is an ObjectInstructor: Dr. X

Page 2: COSC 235: Programming and Problem Solving Ch. 4 or… Everything is an Object Instructor: Dr. X.

Goals

• Understand about objects as computational entities

• Understand and use methods and instance variables

• Use the dot notation• Use the graphics library

Page 3: COSC 235: Programming and Problem Solving Ch. 4 or… Everything is an Object Instructor: Dr. X.

Everything is an Object

https://necessaryagitation.files.wordpress.com/2010/04/objects.gif

Page 4: COSC 235: Programming and Problem Solving Ch. 4 or… Everything is an Object Instructor: Dr. X.

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

Page 5: COSC 235: Programming and Problem Solving Ch. 4 or… Everything is an Object Instructor: Dr. X.

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

Page 6: COSC 235: Programming and Problem Solving Ch. 4 or… Everything is an Object Instructor: Dr. X.

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?

Page 7: COSC 235: Programming and Problem Solving Ch. 4 or… Everything is an Object Instructor: Dr. X.

Everything is an Object

• Objects know stuff – instance variables• Objects can do stuff - methods

Page 8: COSC 235: Programming and Problem Solving Ch. 4 or… Everything is an Object Instructor: Dr. X.

Class

• Determines the methods an object will have• An object is an instance of a class

Page 9: COSC 235: Programming and Problem Solving Ch. 4 or… Everything is an Object Instructor: Dr. X.

Class vs Object

http://www.dgp.toronto.edu/~meng/courses/108/teaching99/lecture/3week/instance_variable.jpg

Page 10: COSC 235: Programming and Problem Solving Ch. 4 or… Everything is an Object Instructor: Dr. X.

Instance Variable

http://www.dgp.toronto.edu/~meng/courses/108/teaching99/lecture/3week/instance_variable.jpg

Page 11: COSC 235: Programming and Problem Solving Ch. 4 or… Everything is an Object Instructor: Dr. X.

Method

getName() getName()setName()setName()

Page 12: COSC 235: Programming and Problem Solving Ch. 4 or… Everything is an Object Instructor: Dr. X.

Constructor

• A “special” method<class-name>(<param1>, <param2>, …)

• It builds objects

http://www.mymoneysocks.com/wp-content/uploads/2015/01/under_construction.jpeg

Page 13: COSC 235: Programming and Problem Solving Ch. 4 or… Everything is an Object Instructor: Dr. X.

Let’s create some clones

Page 14: COSC 235: Programming and Problem Solving Ch. 4 or… Everything is an Object Instructor: Dr. X.

Aliasing vs Cloning

• Alias: two variables refer to the same object• Clone: method that makes a copy of an object

Page 15: COSC 235: Programming and Problem Solving Ch. 4 or… Everything is an Object Instructor: Dr. X.

Graphing Populations

• We will create a similar program as in the book but for populations

• NEED TO WORK ON EXAMPLE!!!

Page 16: COSC 235: Programming and Problem Solving Ch. 4 or… Everything is an Object Instructor: Dr. X.

Event driven programming

• Event ~ Trigger• Event: Object that encapsulates data about

what just happened• Can you thing of example apps that are event

driven?

Page 17: COSC 235: Programming and Problem Solving Ch. 4 or… Everything is an Object Instructor: Dr. X.

Event driven program

• Modify the convert.py to convert_gui.py• Add the option to convert meters to feet!


Recommended