Scope, visibility, and data control
Methods sharing data is important because without it, a method is
just an isolated action that doesn't return anything In some methods, we
see cases where there is no data shared by the method, such as
WriteLine and ReadKey. In these examples, we're not receiving data from
it, but sometimes we pay pass a string or other data type into it. The
"void" return type stated in the heading of a method indicates that
there is no data returned from the method. As I've learned so far
though, there are many, many cases where we want to receive some kind of
value from the method. We want to pass data into the method, perform
some kind of action, and then receive the results of the data after the
action is performed on it. Without data sharing, we lose one of the
fundamentals of object-oriented programming, and would be operating in a
similar fashion as a structured programming language, such as C.
After much research, and sifting through conflicting views, I've found that visibility and scope are closely related, but not exactly the same thing. Scope and visibility are closely related to the object-oriented principle of "data encapsulation" - restricting access to data, and therefore protecting the data.
Scope refers to the block within which a variable "lives." The variable does not exist outside of method, outside of its scope. Once the method has run its course, and the application moves on to the next line in the Main method, the variable no longer "exist" to the rest of the application. It's only relevant within the scope of the method.
Visibility on the other hand refers to the accessibility of a method. When we use public, private, and protected, we're declaring the visibility of the method, and controlling how it can be accessed outside of its scope.
It's important that data can be shared, but it's also important that we as developers are able to control how accessible the data is, and what can modify it. During my research, I found a quote by Linus Torvald, "Bad programmers worry about the code. Good programmers worry about data structures and their relationships." Up until now, I assumed programming was mostly about how eloquent it is. I was mostly interested in looking at the best way to design the algorithm for my code. However, now I'm starting to understand that data is more important than algorithms, and must be tightly controlled. I'm sure I'll find more about this as I move on to more complex applications, but now I know to keep an eye open and an ear perked to learn more about controlling and protecting data.
Sources:
http://www.cplusplus.com/doc/tutorial/namespaces/
http://opensourceforu.efytimes.com/2011/10/joy-of-programming-scope-lifetime-and-visibility-in-c/
http://programmers.stackexchange.com/questions/102041/why-are-data-structures-so-important-in-interviews
After much research, and sifting through conflicting views, I've found that visibility and scope are closely related, but not exactly the same thing. Scope and visibility are closely related to the object-oriented principle of "data encapsulation" - restricting access to data, and therefore protecting the data.
Scope refers to the block within which a variable "lives." The variable does not exist outside of method, outside of its scope. Once the method has run its course, and the application moves on to the next line in the Main method, the variable no longer "exist" to the rest of the application. It's only relevant within the scope of the method.
Visibility on the other hand refers to the accessibility of a method. When we use public, private, and protected, we're declaring the visibility of the method, and controlling how it can be accessed outside of its scope.
It's important that data can be shared, but it's also important that we as developers are able to control how accessible the data is, and what can modify it. During my research, I found a quote by Linus Torvald, "Bad programmers worry about the code. Good programmers worry about data structures and their relationships." Up until now, I assumed programming was mostly about how eloquent it is. I was mostly interested in looking at the best way to design the algorithm for my code. However, now I'm starting to understand that data is more important than algorithms, and must be tightly controlled. I'm sure I'll find more about this as I move on to more complex applications, but now I know to keep an eye open and an ear perked to learn more about controlling and protecting data.
Sources:
http://www.cplusplus.com/doc/tutorial/namespaces/
http://opensourceforu.efytimes.com/2011/10/joy-of-programming-scope-lifetime-and-visibility-in-c/
http://programmers.stackexchange.com/questions/102041/why-are-data-structures-so-important-in-interviews
Comments
Post a Comment