Java Reference
In-Depth Information
Object-Oriented Programming (OOP) Concepts
Object-oriented programming is not just a different set of tools and methods
from traditional structured programming. It represents a different philosophy
about the nature of computer programs and how those programs are assembled.
The following case scenario about two programming students is designed to help
illustrate these differences and provide an analogy for discussing object-oriented
programming constructs.
Object-Oriented Case Scenario
Paul Randall is a student of traditional structured programming. He wants to
create a work/study area in his room where he can write and draw and be able to
store his work. He wants to sit at the work area, write, and then store his papers.
Paul views the system as a set of three functions: sitting, writing, and storing.
After a great deal of effort in drawing up blueprints, Paul has designed a
one-piece integrated study unit, consisting of a writing surface with rolltop
cover, a bench, and two drawers. By designing an integrated unit, the functions
of sitting, writing, and storing will be compatible with each other, and he will
save on material costs and construction time. Paul travels to several lumber and
hardware stores and purchases all the materials.
After considerable construction time, Paul is finished and satisfied with the
result. He can work comfortably and does not need to reach too far to lift up the
desktop or pull open the file drawers. Several weeks pass and Paul begins to think
about making enhancements to his system. His bench is not as comfortable as he
would like, his writing area feels cramped, and his two drawers are full. Paul
decides to live with his system's shortcomings, however, because any change
would require substantial effort to dismantle and rebuild the entire system.
Mary Carter is a student of object-oriented programming. She would like to
have a study area with the same functionality as Paul's study area. Mary, how-
ever, views the system as a set of three objects: a sitting object, a writing surface
object, and a storage object. Even though they are separate objects, Mary is con-
fident she can make them interoperate for an effective study area. Mary travels to
a furniture factory warehouse and begins evaluating the hundreds of different
chairs, desks, and file cabinets for their suitability to her needs and their compat-
ibility with each other.
Mary returns to her room after purchasing a matching chair, two-drawer file
cabinet, and rolltop desk. When the desk handle is pulled, it activates a hardware
mechanism that raises the rolltop. With little effort, Mary's study area is complete.
Although Mary's furniture cost more than Paul's materials, the savings on
her labor costs have more than made up the difference. After several weeks,
Mary's file cabinet is full. She returns to the furniture store, buys a three-drawer
cabinet of the same style, and replaces the one in her study area.
Encapsulation, Inheritance, and Polymorphism
The conceptual constructs, or building blocks, of object-oriented programming
and design include encapsulation, inheritance, and polymorphism. These tools
assist programmers with reusing code, and help them create prebuilt objects for
rapid application development.
Search WWH ::




Custom Search