OOP Lecture 06. OOP? Stands for object oriented programming. You’ve been using it all along....
-
Upload
laurence-golden -
Category
Documents
-
view
213 -
download
0
Transcript of OOP Lecture 06. OOP? Stands for object oriented programming. You’ve been using it all along....
OOPLecture 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)
ClassesAll objects belong to a classObjects are instances of a classClasses are like a blueprint for objects
Making Classes
class Ball(): def __init__(self, name): self.bounce = False self.name = name
AbstractionGetting all the necessary information for you needs.
Adding Methods
class Ball(): def __init__(self, name): self.bounce = 5 self.name = name def bounce_ball(self): self.bounce = True
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
Calling MethodsMethods are functions on objects.We call them using the ‘.’ operator
Student Class
Inheritance