The Blueprint Analogy
Why use Object Oriented Programming
One of the fundamental concepts that makes OOP so popular is known as data encapsulation. We have already discussed how a variable can have a greater or lesser scope depending on where it is declared, that is to say that when a variable is not declared within the global variable scope it can only be accessed in some parts of a program and not in others that are outside of the structure in which it was declared. The range over which the variable is accessible refers to the variable's scope. Data encapsulation is a similar concept, except that the concept of “hiding” data is emphasized as opposed to defining a variable in the global variable scope where the concept of “exposing” data is emphasized. Another major difference between the two concepts is that with data encapsulation as opposed to variable scope we are not referring to a single variable but can, in fact, be referring to entire structures. These structures that we make inaccessible to the main program are what form the body of code that defines a class. By defining a class we use a modular approach to designing software, in the sense that the class that we have defined is not necessarily specific to the program we initially wrote it for, and as a result can be used in our program or removed from our program without us having to rewrite the entire program this is an inherent design characteristic of data encapsulation. Amongst other applications, creating a class defines the behaviors that an object instantiated from it will inherit. In order to interact with an object in a program, and subsequently use that which it has inherited from a class, we interact with the object via it's behaviors which are more commonly referred to as methods. This is a form of data encapsulation, in that we do not have direct access to how that object works as that is defined within the class. However we can still have the object interact with our main program through it's methods. In this sense Object Oriented Programming can provide a level of abstraction, when working with objects in the main program.