A good example of the use of this technique is in the file commandsyou have been using with ANSI-C. The data in the file is onlyavailable through the predefined functions provided by yourcompiler writer. You have no direct access to the actual databecause it is impossible for you to address the actual data storedon the disk. The data is therefore private data, as far as you areconcerned, but the available functions are very much like methodsin C++. There are two aspects of this technique that really countwhen you are developing software. First, you can get all of thedata you really need from the file system because the interface iscomplete, but secondly, you cannot get any data that you do notneed. You are prevented from getting into the file handling systemand accidentally corrupting some data stored within it. You arealso prevented from using the wrong data because the functionsavailable demand a serial access to the data.

Another example is in the monitor and keyboard handling routines.You are prevented from getting into the workings of them andcorrupting them accidentally, or on purpose if you have such abent, but once again, you are provided with all of the datainterfaces that you really need.

Suppose you are developing a program to analyze somecharacteristics of flagpoles. You would not wish to accidentallyuse some data referring to where the flagpole program was storedon your hard disk as the height of the flagpole, nor would you wishto use the cursor position as the flagpole thickness or color. Allcode for the flagpole is developed alone, and only when it isfinished, is it available for external use. When using it, youhave a very limited number of operations which you can do with theclass. The fact that the data is hidden from you protects you fromaccidentally doing such a thing when you are working at midnightto try to meet a schedule. Once again, this is referred to asinformation hiding and is one of the primary advantages of objectoriented programming over procedural techniques.

Based on the discussion given above you can see that objectoriented programming is not really new, since it has been used ina small measure for as long as computers have been popular. Thenewest development, however, is in allowing the programmer topartition his programs in such a way that he too can practiceinformation hiding and reduce the debugging time.


It should be clear that this technique will cost you something inefficiency because every access to the elements of the object willrequire the time and inefficiency of a call to a function, orperhaps I should be more proper and refer to it as a method. The

time saved in building a large program, however, could easily besaved in debug time when it comes time to iron out the last fewbugs. This is because a program made up of objects that closelymatch the application are much easier to understand than a programthat does not.

This is obviously such a small program that it is silly to try tosee any gain with this technique. In a real project however, itcould be a great savings if one person developed all of the detailsof the rectangle, programmed it, and made it available to you tosimply use. This is exactly what has been done for you if youconsider the video monitor an object. There is a complete set ofpreprogrammed and debugged routines you can use to make the monitordo anything you wish it to do, all you have to do is study theinterface to the routines and use them, expecting them to work.As we mentioned earlier, it is impossible for you to multiply thesize of your monitor screen by the depth of the flag pole becausethat information is not available to you to use in a corruptibleway.

After you understand some of the advantages of this style of programming, be sure to compile and execute this program.