Getting to know methods
The term method has been thrown around a few times thus far in the book. A method is a special type of function that belongs to a function block. Methods are members of function blocks that consist of blocks of code that are executed when called. Without methods, a function block is mostly useless. To conceptualize a method, consider the blueprint example before. If the function block is a car, then the methods are the brakes and engine of said car.
Unlike the functions we explored in Chapter 5, methods are not global. This means that they cannot be called from anywhere like the functions we previously explored. Essentially, the only place that can call these functions is a file with an object to the function block or from somewhere inside the function block, such as another method.
To create a method, you must first have a function block. Since we already have a Calculator
function block, we are going to add four methods to it that will handle addition...