Download presentation
Presentation is loading. Please wait.
Published byLaurence Golden Modified over 9 years ago
1
OOP Lecture 06
2
OOP? Stands for object oriented programming. You’ve been using it all along. Anything you use the dot ‘.’ on is an object.
3
Methods and Variables Objects have methods and variables # Getting a variable self.rect.x # Using a method mylist.append(54) # Getting a variable self.rect.x # Using a method mylist.append(54)
4
Classes All objects belong to a class Objects are instances of a class Classes are like a blueprint for objects
5
Making Classes class Ball(): def __init__(self, name): self.bounce = False self.name = name class Ball(): def __init__(self, name): self.bounce = False self.name = name
6
Abstraction Getting all the necessary information for you needs.
7
Adding Methods class Ball(): def __init__(self, name): self.bounce = 5 self.name = name def bounce_ball(self): self.bounce = True class Ball(): def __init__(self, name): self.bounce = 5 self.name = name def bounce_ball(self): self.bounce = True
8
Using the Classes This means instantiating them, and creating different versions of them ball1 = Ball("Tennis") ball2 = Ball("Basket") ball3 = Ball("Base") ball1.bounce_ball() print ball1.name print ball1.bounce print ball2.bounce ball1 = Ball("Tennis") ball2 = Ball("Basket") ball3 = Ball("Base") ball1.bounce_ball() print ball1.name print ball1.bounce print ball2.bounce
9
Calling Methods Methods are functions on objects. We call them using the ‘.’ operator
10
Student Class
11
Inheritance
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.