We have seen that a Method or a Function can be used to arrive at the same result. So, does it matter which we use? In the situation we just examined, counting the characters in an EditField, we could use either approach. However, suppose we wanted to count the characters in a number of different EditFields.


The Method Approach

To count the characters in each of the three fields we would need three different methods. Each method would be similar but not identical. The code in the Count PushButton would look like this:


We have called three different methods, sending each method a different parameter. Each of the three methods would be similar to the following:


The Function Approach

If we take the function approach we only need one function to get all three character counts. In the Count button we would put the following:


We have called the same function three times, each time with a different parameter. 
The CountCharacters function would have the following code:


In the above there really isn’t much difference in the two approaches with regard to the amount of code involved. However, with more complex methods, having to create three similar but separate methods would be a pain. Using a single function is a much more elegant way to go.

In general, we can say that functions tend to be more generic and, therefore, more easily re-used than methods. On the other hand, methods often have the advantage of being more specific to a given situation.

Which approach you take will depend on the characteristics of the situation you are trying to deal with.