Oops+Python
Oops+Python
Examples:
● Byte
● Int
● Float
● Boolean
● Double
● Char
What is OOP? - Primitive Data
The Structure
Int Int
String double
What is OOP? - The Structure
Struct Knight
Position Color
Captured
What is OOP? - The Structure
Struct Knights
Knight 1 Knight 2
Knight 3 Knight 4
What is OOP? - The Structure
Struct Struct
WhiteKnights BlackKnights
Knight 1 Knight 2
Knight 3 Knight 4
What is OOP? - The Structure
Class knight
Function is specific to
move()
knights, as other pieces
move in a different
manner
What is OOP? - Classes
Class knight
move() position
data function
data function
function data data function
data function data function
Series - Overview
Retrieving
Changing information
information
What is OOP? - Classes
piece.getColor()
Method 1 Method 2
Encapsulation - Game Example
Class Player
Player.maxHealth Player.levelUp()
currentHealth maxHealth
Encapsulation - Game Example
def setCurrentHealth(newHealth):
player.currentHealth = newHealth
if player.currentHealth > player.maxHealth:
player.currentHealth = player.maxHealth
Encapsulation - Methods
Class Piece
Piece.rank
Player.file
Encapsulation - Game Example
Class Piece
Piece.rank
Player.file
Encapsulation - Game Example
Class Piece
Piece.rank =newRank
Player.file =newFile
Encapsulation - Game Example
Class Piece
Piece.rank =newRank
Player.file =newFile
Encapsulation - Game Example
Class Piece
Piece.rank piece.move()
Each piece should not have access to or rely on the inner working of
other sections of code
Encapsulation - Information Hiding
Encapsulation:
As long as you
understand the outcome,
the process is not very Important to most people
important to you
Abstraction - Explanation
The classes you create should act like your car. Users
of your classes should not worry about the inner
details of those classes
Abstraction - Explanation
Interface
Implementation
Abstraction - Interface and Implementation
Car moves
car.pushGas()
forward
Interface
Abstraction - Chess Example
information
King’s methods
Interface
Abstraction - Chess Example
information
King’s methods
Interface
information
King’s methods
Abstraction - Chess Example
King’s implementation is not
important to you
information
King’s methods
Interface
information
King’s methods
Abstraction - Interface and Implementation
Data 1 Data 1
Data 2 Data 2
Data 3 Data 3
Abstraction - Interface and Implementation
Data 1 Data 2
Data 2 Data 1
Data 3 Data 3
Abstraction - Interface and Implementation
Data 1 Data 2
Data 2 Data 1
Data 3 Data 3
Abstraction - Interface and Implementation
Class weapon
Class weapon
Subclass Subclass
Class Weapon
Superclass
Subclass Subclass
Inheritance - Access Modifiers
Food
Fruit Vegetables
Food
Fruit Vegetables
Food
Fruit Vegetables
Food
Fruit Vegetables
.drive(miles) .drive(miles)
.drive(miles) .drive(miles)
mySportsCar.drive()
Polymorphism - Car Example
.drive(miles) .drive(miles)
mySportsCar.drive()
Polymorphism - Car Example
.drive(miles) .drive(miles)
myCar.drive()
Polymorphism - Car Example
.drive(miles) .drive(miles)
myCar.drive()
Polymorphism - Dynamic
Class Car
Class sportsCar
Class Car
Class Car
Class Car
Class Car
Class Car
Class Car