23.11.2014 Views

Data Structures and Algorithms in Java[1].pdf - Fulvio Frisone

Data Structures and Algorithms in Java[1].pdf - Fulvio Frisone

Data Structures and Algorithms in Java[1].pdf - Fulvio Frisone

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Modularity<br />

In addition to abstraction <strong>and</strong> encapsulation, a fundamental pr<strong>in</strong>ciple of object<br />

oriented design is modularity. Modern software systems typically consist of<br />

several different components that must <strong>in</strong>teract correctly <strong>in</strong> order for the entire<br />

system to work properly. Keep<strong>in</strong>g these <strong>in</strong>teractions straight requires that these<br />

different components be well organized. In object-oriented design, this code<br />

structur<strong>in</strong>g approach centers around the concept of modularity. Modularity refers<br />

to an organiz<strong>in</strong>g pr<strong>in</strong>ciple for code <strong>in</strong> which different components of a software<br />

system are divided <strong>in</strong>to separate functional units.<br />

Hierarchical Organization<br />

The structure imposed by modularity helps to enable software reusability. If<br />

software modules are written <strong>in</strong> an abstract way to solve general problems, then<br />

modules can be reused when <strong>in</strong>stances of these same general problems arise <strong>in</strong><br />

other contexts.<br />

For example, the structural def<strong>in</strong>ition of a wall is the same from house to house,<br />

typically be<strong>in</strong>g def<strong>in</strong>ed <strong>in</strong> terms of 2- by 4-<strong>in</strong>ch studs, spaced a certa<strong>in</strong> distance<br />

apart, etc. Thus, an organized architect can reuse his or her wall def<strong>in</strong>itions from<br />

one house to another. In reus<strong>in</strong>g such a def<strong>in</strong>ition, some parts may require<br />

redef<strong>in</strong>ition, for example, a wall <strong>in</strong> a commercial build<strong>in</strong>g may be similar to that<br />

of a house, but the electrical system <strong>and</strong> stud material might be different.<br />

A natural way to organize various structural components of a software package is<br />

<strong>in</strong> a hierarchical fashion, which groups similar abstract def<strong>in</strong>itions together <strong>in</strong> a<br />

level-by-level manner that goes from specific to more general as one traverses up<br />

the hierarchy. A common use of such hierarchies is <strong>in</strong> an organizational chart,<br />

where each l<strong>in</strong>k go<strong>in</strong>g up can be read as "is a," as <strong>in</strong> "a ranch is a house is a<br />

build<strong>in</strong>g." This k<strong>in</strong>d of hierarchy is useful <strong>in</strong> software design, for it groups<br />

together common functionality at the most general level, <strong>and</strong> views specialized<br />

behavior as an extension of the general one.<br />

Figure 2.3: An example of an "is a" hierarchy<br />

<strong>in</strong>volv<strong>in</strong>g architectural build<strong>in</strong>gs.<br />

94

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!