Skip to main content

Posts

Showing posts from April, 2016

The importance of sharing data between functions/methods, and their scope.

It is important that functions/methods share data between a class because in programming you will be having a lot of methods that will need to share data to function correctly. For example, if you had to calculate different types of data with equations, you would have the calculations being done in one method then transfer only the calculated data to a display method. If data isn't shared between these two classes then only the calculation method will have the data, and no other methods can access it, making it difficult to use that data to perform more tasks. The scope refers to the portion of the program a variable is visible, as well as where it can only be used. It is referred to where a variable can be read from and/or written to, in other words where the variable lives. Visibility compared to scope is where the variables can be used and shared. We can set where a variable can be accessed with three different options, public, private and protected. This is important becau