and let the computer and the programming language worry about which representation to use and how to perform the given operations.” This is precisely the point behind encapsulation. The details of how signed integers are interpreted by the computer (and the compiler), as well as how their properties and operations are implemented, are encapsulated in the integer data type itself and are thus hidden from us, the users of the data type. Only those portions of the properties and operations that we need in order to work with integers are exposed outside of the data type. These portions form the public interface for the Integer data type. Moreover, encapsulation protects us from making errors. For instance, if we had to do our own negating by taking Boolean complements and adding 1, we might forget to add 1! The encapsulated data type takes care of this automatically. Encapsulation has yet another important feature. Any code that is written using the exposed interface remains valid even if the internal workings of the Integer data type are changed for some reason, as long as the interface is not changed. For instance, if we move the code to a computer that stores integers in one’s-complement representation, then the internal procedure for implementing the operation of negation in the integer data type will have to be changed. However, from the programmer’s point of view, nothing has changed. The code: x = -16 y = -x is just as valid as before. 3.2.3 Interfaces As VB programmers, we must implement encapsulation through the use of software components. For instance, we can create a software component to encapsulate the Employee abstraction discussed earlier. In VB .NET, the methods of an interface are realized as functions. On the other hand, a property, as we see later in this chapter, is realized as a private variable that stores the property’s value together with a pair of public functions one to set the variable and one to retrieve the variable. These functions are sometimes referred to as accessor methods of the property. It is the set of exposed functions (ordinary methods and accessor methods) that constitute the interface for an abstraction. In general, a software component may encapsulate and expose more than one abstraction hence, more than one interface. For example, in a more realistic setting, we might want a software component designed to model employees to encapsulate an interface called IIdentification (the initial “I” is for interface) that is used for identification purposes. This interface might have properties such as Name, Social Security number, Driver’s License number, Age, Birthmarks, and so on. Moreover, the software component might also encapsulate an interface called IEducation for describing the employee’s educational background. Such an interface might implement properties such as Education Level, Degrees, College Attended, and so on. The interface of each abstraction exposed by a software component is also referred to as an interface of the software component. Thus, the Employee component implements at least two interfaces: IIdentification and IEducation. Note, however, that the term interface is often used to refer to the set of all exposed properties and methods of a software component, in which case a component has only one interface. Referring to our original Employee abstraction, its interface might consist of the functions shown in Table 3-1. (Of course, this interface is vastly oversimplified, but it is more than sufficient to illustrate the concepts.)
Hint: If you are looking for high quality and reliable webspace provider to host and run your jsp hosting application check Virtualwebstudio jsp web hosting provider