Professional Documents
Culture Documents
Materi Pertemuan 2 - OOP 2
Materi Pertemuan 2 - OOP 2
Materi Pertemuan 2 - OOP 2
• Extensibility: programmers can create new methods or change existing ones as desired without having to
create code from scratch,
• Maintainability: code that has been made is easier to manage if the application is made on a large scale
which allows for errors in its development, this can be overcome with OOP because OOP programming
already uses the concept of modularity
• Adi
Object: is an instance or detail of a class • Ani
• It has a unique value according to the class property and can • Abi
perform methods from the class.
Human Class Object
Example:
• Adi, Ani, Abi is object form Human Class
• Avanza, Inova, Supra is object from Car Class,
• Table, Chair, Door from Product Class
# constructor of class
def __init__(self, name, address, religion):
# attribute
self.name = name
self.address = address
self.religion = religion
# constructor of class
def __init__(self, name, address, religion):
# attribute
self.name = name
self.address = address
self.religion = religion
def walk(self):
print("I'm "+self.name+", I can walk")
Example:
• Human is Parent Class
• Lecturer is Child Class from Human Class • Adi
• Ani
• Lecturer Class is inheritance from the Human Class • Abi
Lecturer Class Object
Example:
• Human can be Lecturer and Teacher
• Lecturer has walk method and Teacher has walk method
Lecturer Class
name
address
Human Class
Attribute walk
breathe
eat Teacher Class
Method
Example:
• Human must have a name, address
• Actually humans also have an age attribute,
• it's just that people don't really like being asked about age because it's a private matter
name
address
age Human Class
Attribute walk
breathe
eat
Method
# attribute # getter
self.name = None print(lec1.get_religion())
self._address = None
self.__religion = None
def get_religion(self):
return self.__religion
Example:
• Every human has a soul
• And every soul has a heart and how he believes
name
address
age Human Class
Attribute walk
Soul Class breathe
eat
heart believe
Method
Attribute Method
def display_info(self):
print("I'm Lecturer")
Any Question?
Assignment
• Explain the many examples of the basic OOP concepts we have studied.