Use of object oriented techniques.
2.2.1 Programming Techniques
Programming Techniques — Note 6 of 6
Candidates need to understand classes, objects, attributes, methods, encapsulation (including get and set methods), inheritance and polymorphism. Candidates need to be able to read, trace and write object-oriented code, interpret class diagrams to produce class definitions, and derive an object-oriented solution for a given scenario.
Object-oriented techniques are used to design and write programs as collections of interacting objects. You need to read, trace and write OOP code, interpret class diagrams, and decide when an object-oriented approach suits a problem.
draw().Exam tipCommon mistake
A diagram showing each class's name, attributes and methods (with + for public and - for private), and arrows showing inheritance.
class Shape:
def __init__(self, name):
self.__name = name # private attribute
def get_name(self): # getter
return self.__name
def area(self):
return 0
class Rectangle(Shape): # inheritance
def __init__(self, width, height):
super().__init__("Rectangle")
self.width = width
self.height = height
def area(self): # overrides Shape.area (polymorphism)
return self.width * self.height
shapes = [Shape("Blank"), Rectangle(3, 4)]
for s in shapes:
print(s.get_name(), s.area()) # Blank 0, then Rectangle 12