Lec 2
Lec 2
def get_brand(self):
return self.__b
Accessors and mutators
• Python offers another approach called properties
• A method which is used for getting a value is decorated with
"@property“
• The method which has to function as the setter is decorated
with "@x.setter"
Accessors and mutators
class Car: c = Car("Toyota")
def __init__(self, brand): print(c.brand)
self.__b = brand c.brand = "Audi"
@property
def brand(self):
return self.__b
@brand.setter
def brand(self, brand):
self.__b = brand
Class Diagrams
• Class diagrams describes the set of
classes in a system
• Also shows attributes and operations
of each class
• Inheritance shown with arrows
towards parent class
Class Diagrams
• Visibility of attributes/operations
− Public attributes (+): visible to all
classes
− Private/protected attributes (-): visible
only to an instance of the class in
which they are defined
• UML notation
☑ OOP
☑ Inheritance
☑ Polymorphism
☑ Encapsulation
Summary