3 - Object Oriented Programming
3 - Object Oriented Programming
• Procedural • Object-Oriented
programming Programming
– Real-world concept
• Entity, attribute and relationship
– Reusability
• Object/Instance
– Represent the actual thing
– Cannot change the type of characteristics
– But can define the actual values
Define a class
• class class_name(parent_class_name):
variable1 = 0
variable2 = “Wall”
• Declaration:
– object_name = class_Name();
– Object_name.method_name();
Example: Drawing class and instances
• Create a class to represent the attributes of drawings
• Method
– Calculate the total cost
Initialization method
• __init__()
– Examples
Package
• A mechanism for organizing the modules. Just like
the file folder for classes.
• Examples
Method override – Polymorphism
• The method from a super class is modified in the
subclasses