Java Reference
In-Depth Information
3.2
Abstraction and modularization
A first idea might be to implement the whole clock display in a single class. That is, after all,
what we have seen so far: how to build classes to do a job.
However, here we shall approach this problem slightly differently. We will see whether we can
identify subcomponents in the problem that we can turn into separate classes. The reason is
complexity. As we progress in this topic, the examples we use and the programs we build will
get more and more complex. Trivial tasks such as the ticket machine can be solved as a single
problem. You can look at the complete task and devise a solution using a single class. For more
complex problems, that is too simplistic. As a problem grows larger, it becomes increasingly
difficult to keep track of all details at the same time.
The solution we use to deal with the complexity problem is abstraction. We divide the problem
into sub-problems, then again into sub-sub-problems, and so on, until the individual problems
are small enough to be easy to deal with. Once we solve one of the sub-problems, we do not
think about the details of that part any more, but treat the solution as a single building block for
our next problem. This technique is sometimes referred to as divide and conquer.
Concept:
Abstraction is
the ability to ignore
details of parts, to
focus attention on
a higher level of a
problem.
Let us discuss this with an example. Imagine engineers in a car company designing a new car.
They may think about the parts of the car, such as the shape of the outer body, the size and loca-
tion of the engine, the number and size of the seats in the passenger area, the exact spacing of
the wheels, and so on. Another engineer, on the other hand, whose job is to design the engine
(well, that's a whole team of engineers in reality, but we simplify this a bit here for the sake of
the example), thinks of the many parts of an engine: the cylinders, the injection mechanism, the
carburetor, the electronics, etc. She will think of the engine not as a single entity, but as a com-
plex work of many parts. One of these parts may be a spark plug.
Then there is an engineer (maybe in a different company) who designs the spark plugs. He will
think of the spark plug as a complex artifact of many parts. He might have done complex stud-
ies to determine exactly what kind of metal to use for the contacts or what kind of material and
production process to use for the insulation.
The same is true for many other parts. A designer at the highest level will regard a wheel as a
single part. Another engineer much further down the chain may spend her days thinking about
the chemical composition necessary to produce the right materials to make the tires. For the tire
engineer, the tire is a complex thing. The car company will just buy the tire from the tire com-
pany and then view it as a single entity. This is abstraction.
The engineer in the car company abstracts from the details of the tire manufacture to be able to
concentrate on the details of the construction of, say, the wheel. The designer designing the body
shape of the car abstracts from the technical details of the wheels and the engine to concentrate on
the design of the body (he will just be interested in the size of the engine and the wheels).
Concept:
Modularization
is the process of
dividing a whole
into well-defined
parts that can be
built and examined
separately and that
interact in well-
defined ways.
The same is true for every other component. While someone might be concerned with design-
ing the interior passenger space, someone else may work on developing the fabric that will
eventually be used to cover the seats.
The point is, if viewed in enough detail, a car consists of so many parts that it is impossible for
a single person to know every detail about every part at the same time. If that were necessary,
no car could ever be built.
 
 
Search WWH ::




Custom Search