OOP Workshop

Draw Button Method

def drawTheButton(self, aTurtle):

        global selectedButton 
        if(self is selectedButton):
            aTurtle.color("Red")
        else:
            aTurtle.color("Black")
            
        aTurtle.setheading(0)
        aTurtle.fillcolor(self.buttonColor)
        aTurtle.penup()
        aTurtle.goto(self.buttonX, self.buttonY)
        aTurtle.pendown()
        
        aTurtle.begin_fill()
        
        self.drawButtonShape(aTurtle) # Potential Polymorphic call to child class
        
        aTurtle.end_fill()

drawTheButton method takes care of adding different button types on the screen. The 'drawButtonShape' method has a polymorphic call inside this method, that will act differently for each type of the inheriting methods, without the need to know the details of the implementation in those child classes. Even though the drawTheButton function will not be modified by the child classes, any call to this function will determine the correct implementation of the drawButtonShape method with respect to the child class instantiated for that specific button type.