Skip to main content

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 because if set a variables access to public instead of private in a class then all of the methods inside that class will have the liberty to use that variable. This can create issues with bigger programs as the data can be changed and overwritten since the access is easy to use for multiple methods. If the access is private then only a specific method can use that variable(s), which is better when you want to protect that data from being used in other methods.


sources:
https://msdn.microsoft.com/en-us/library/ms973875.aspx
https://msdn.microsoft.com/en-us/library/awt60xs1.aspx

Comments

Popular posts from this blog

Your Online Life, Permanent As a Tattoo

View TED Talk Link Watching this TED talk titled “Your Online Life, Permanent As a tattoo” talks about how the use of social media can be the same as having a personal tattoo. Juan Enriquez, the main speaker, begins the presentation by using visual pictures of what tattoos can represent in a person's life. Using pictures, he shows the audience that tattoos can be beautiful, intriguing, intimate and also builds humor by stating that they can be mistakes. After showing the audience these different types of tattoos, he starts to question them about what if social sites and services were to become personal tattoos. At this point he begins to add more information on how the way we express ourselves on  social media can impact and create our  “Electronic Tattoo”. Juan states how difficult it is to get away from our electronic tattoos, since forms of technology, like facial recognition are getting better and better at recognizing people's faces. He adds up that if someone...

Modular Programming

Modular programming is the practice of breaking down a program's functionality into independent interchangeable modules. Each of these modules have everything necessary to execute only that aspect of the desired functionality, in the case they are needed.  Modular programming is important because it creates a structure that keeps the code organized and easier to maintain. For example, if you had to change an object used throughout a program, with modular programming you would only have to find the module where the character was coded. Compared to not having modularization, if you wanted to accomplish this you would be required to read the code line by line having to find and edit that character everywhere it was used. Programming languages like C#, java, and C have this implemented by having different methods or identifiers. Once that is created then you are able to use those methods elsewhere in your code, which also saves time by not having to re-write the method all over ag...