OOP Lecture 06. OOP? Stands for object oriented programming. You’ve been using it all along....

11
OOP Lecture 06

Transcript of OOP Lecture 06. OOP? Stands for object oriented programming. You’ve been using it all along....

Page 1: OOP Lecture 06. OOP? Stands for object oriented programming. You’ve been using it all along. Anything you use the dot ‘.’ on is an object.

OOPLecture 06

Page 2: OOP Lecture 06. OOP? Stands for object oriented programming. You’ve been using it all along. Anything you use the dot ‘.’ on is an object.

OOP?Stands for object oriented programming.You’ve been using it all along.Anything you use the dot ‘.’ on is an object.

Page 3: OOP Lecture 06. OOP? Stands for object oriented programming. You’ve been using it all along. Anything you use the dot ‘.’ on is an object.

Methods and Variables Objects have methods and variables

# Getting a variableself.rect.x # Using a methodmylist.append(54)

Page 4: OOP Lecture 06. OOP? Stands for object oriented programming. You’ve been using it all along. Anything you use the dot ‘.’ on is an object.

ClassesAll objects belong to a classObjects are instances of a classClasses are like a blueprint for objects

Page 5: OOP Lecture 06. OOP? Stands for object oriented programming. You’ve been using it all along. Anything you use the dot ‘.’ on is an object.

Making Classes

class Ball():   def __init__(self, name):      self.bounce = False      self.name = name

Page 6: OOP Lecture 06. OOP? Stands for object oriented programming. You’ve been using it all along. Anything you use the dot ‘.’ on is an object.

AbstractionGetting all the necessary information for you needs.

Page 7: OOP Lecture 06. OOP? Stands for object oriented programming. You’ve been using it all along. Anything you use the dot ‘.’ on is an object.

Adding Methods

class Ball():   def __init__(self, name):      self.bounce = 5      self.name = name   def bounce_ball(self):      self.bounce = True

Page 8: OOP Lecture 06. OOP? Stands for object oriented programming. You’ve been using it all along. Anything you use the dot ‘.’ on is an object.

Using the ClassesThis means instantiating them, and creating different versions of them

ball1 = Ball("Tennis")ball2 = Ball("Basket")ball3 = Ball("Base") ball1.bounce_ball()print ball1.nameprint ball1.bounceprint ball2.bounce

Page 9: OOP Lecture 06. OOP? Stands for object oriented programming. You’ve been using it all along. Anything you use the dot ‘.’ on is an object.

Calling MethodsMethods are functions on objects.We call them using the ‘.’ operator

Page 10: OOP Lecture 06. OOP? Stands for object oriented programming. You’ve been using it all along. Anything you use the dot ‘.’ on is an object.

Student Class

Page 11: OOP Lecture 06. OOP? Stands for object oriented programming. You’ve been using it all along. Anything you use the dot ‘.’ on is an object.

Inheritance