Objects as Multiple Entities

   

One of the pitfalls for procedural programmers is that of thinking of a data structure in a program as representing a single entity. A perfect example of this is the display screen. Usually, procedural programs tend to write something to the (one) screen. The problem with this method is that when you switch to a windowing environment and have to write to multiple screens, the whole program is in jeopardy. It takes a lot of work to go back and change the program so that the correct data is written to the appropriate window.

In contrast, OOP programming simplifies the task of treating the screen not as the screen but as a screen. Adding windows is as simple as telling an output method which screen object to use.

This demonstrates one of the aspects of OOP that has the potential to save a great deal of programming time. OOP programmers think of the problems they are solving with software in the context of a relevant set of objects. No matter if you're working with 1 or 100 objects of a single type, it doesn't affect how a program interacts with any one of those objects at all. If you're not familiar with OOP programming, this might not make sense yet. You might be thinking "If I have two screens, when I print something to the screen, I need to position it on the correct screen, and then handle user interaction with each screen separately."

The key point here is that OOP removes the need to constantly address this multiplicity of objects in your code. After the elements of a window or screen are abstracted sufficiently, you can write an output method that writes to the window it's directed to without being concerned about which one it is. The window object referenced by the method takes care of the details of providing the required output functionality. Now, obviously there is still the need to implement some controller functionality that determines which window to direct an output method to use, and to handle any interaction between windows. However, this functionality can be written once and maintained independently of the window objects and output methods . The knowledge of multiple entities is completely decoupled from the entities themselves .

   


Special Edition Using Java 2 Standard Edition
Special Edition Using Java 2, Standard Edition (Special Edition Using...)
ISBN: 0789724685
EAN: 2147483647
Year: 1999
Pages: 353

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net