The Three Greatest Paragraphs Ever Written on Encapsulation
Join the DZone community and get the full member experience.Join For Free
encapsulation isn't sexy.
it's the chartered accounting of software design.
functional java programming? formula freakin' one. hybrid cloud computing? solid booster rockets exploding on a midnight launch-pad. but encapsulation?
do not confuse, however, this lack of oomph with lack of importance. invaluable invisible support systems surround us. try living without plumbing for a week. or electricity.
coupled with its rather sorry pr encapsulation groans under a second burden, that of ambiguity. every programmer has her or his own definition of what encapsulation is. most resemble one another, many overlap, but some do little more than reflect randomly-acquired habit.
yet if we are to discuss the three greatest encapsulation paragraphs we surely need a definition. you may not agree with it but you should at least be in a position to judge the degree to which those paragraphs accord with this definition.
how, then, do we solve this ambiguity? it would be nice if there were an international, standard definition of encapsulation upon which to construct our investigation but for this to be the case would require an international organization for standardization, and this international organization for standardization would have had to define, "encapsulation," in some meaningful way.
well - would you believe it? - there actually is such an international organization for standardization.
it's called the, "international organization for standardization."
and these good people have officially defined encapsulation (in iso/iec 10746-3 ) as being:
encapsulation : (drum roll) the property that the information contained in an object is accessible only through interactions at the interfaces supported by the object (cymbal crash!).
(sound effects added by the author.)
yes, yes, that's not your definition. and it begs all sorts of questions. and it defines notions in terms of other, equally-nebulous notions. you are asked, however, not to mindlessly replace your own definition with the above but merely to consider it plausible for this article's duration. use it as a tool to crack the shells of the paragraphs to come then toss it aside if you wish. it issues, after all, from the people whose food health-regulations ensured that the breakfast you ate this morning was relatively safe. let us lend them our ears even if we take them back when they are finished.
separation of concerns.
august 30th, 1974.
you can still catch, "the godfather: part ii," in the cinema, paul anka croons away at the top of the u.s.a music charts and the nevada desert shrieks as a two-hundred kiloton blast splatters radioactive debris over its vitrifying sands.
meanwhile in the netherlands, professor edsger dijkstra completes the week by typing another essay. renowned in computing circles and recipient of the prestigious a. m. turing award a couple of years earlier, dijkstra has been writing insightful essays on computing for over a decade, some - such as the infamous go to statement considered harmful - generating among enthusiasts as much enmity as respect.
today's essay is called on the role of scientific thought . it is perhaps a tad wordy, a tad meandering, yet it harbours a core of profound genius. the first of our three greatest paragraphs on encapsulation, the text needs nothing of the context of its surrounding essay to make itself understood:
"let me try to explain to you, what to my taste is characteristic for all intelligent thinking. it is, that one is willing to study in depth an aspect of one's subject matter in isolation for the sake of its own consistency, all the time knowing that one is occupying oneself only with one of the aspects. we know that a program must be correct and we can study it from that viewpoint only; we also know that it should be efficient and we can study its efficiency on another day, so to speak. in another mood we may ask ourselves whether, and if so: why, the program is desirable. but nothing is gained —on the contrary!— by tackling these various aspects simultaneously. it is what i sometimes have called "the separation of concerns", which, even if not perfectly possible, is yet the only available technique for effective ordering of one's thoughts, that i know of."
here, dijkstra whispers for the first time the phrase, "separation of concerns," little knowing that his voice would still reverberate through our digital cloisters almost forty years later.
for who has not heard of the separation of concerns? and who would dream of understanding any non-trivial source code by consuming it in one, mighty brain-gulp rather than slicing it asunder to dissect its individual requirements, its features, its packages or its sub-structures?
dijkstra was not, however, discussing encapsulation specifically, so how can this be one of the greatest paragraphs on encapsulation? this is an encapsulation piece in that it underwrites encapsulation's claim that an object's information is separate from its interfaces. indeed, encapsulation merely celebrates and exploits this separability without which it would slump de-fanged, a forgotten curiosity.
today, we think this all obvious. what's the big deal? such is the mark of a great idea: it is difficult to conceive of a world in which that idea plays no part. we'll encounter this plight again.
two years before dijkstra clickity-clacked out his masterpiece, canadian david parnas had already lit upon a gem of his own. (our journey declines along an axis of the conceptually abstract rather than the chronological.)
parnas - like dijkstra, a university lecturer - published his on the criteria to be used in decomposing systems into modules in december, 1972.
in his paper parnas describes how to build a software system and concludes with the second of our three greatest paragraphs:
"we have tried to demonstrate by these examples that it is almost always incorrect to begin the decomposition of a system into modules on the basis of a flowchart. we propose instead that one begins with a list of difficult design decisions or design decisions which are likely to change. each module is then designed to hide such a decision from the others."
witness the birth of information-hiding and wonder no more whence java's
modifier comes. if some doubt surrounded the relevance of dijkstra's contribution, here is the very essence of encapsulation; for what restricts access to interfaces but that the object's information is, in some sense, hidden whereas the interfaces are not?
as with separation of concerns, information-hiding seems mundane to us now as steel to the builders of skyscrapers; few rivets clang home to iron-age thoughts. programming boasts no such longevity, of course, yet forty years of searching has failed to produce information-hiding's successor.
figure 3: wayne stevens.
our third and final greatest paragraph springs from not one soul but three. in a paper entitled structured design written for the ibm systems journal, w. stevens, g. myers and l. constantine introduced a wealth of extraordinary ideas to the computing universe of 1974. (what was it about the seventies that nurtured such innovation? the flares? the handlebar mustaches? the brownness?)
while separation of concerns and information-hiding provided the foundational mechanisms by which encapsulation is realised, the structured design paper crystallized the criteria by which the deployment of these mechanisms might be judged. again, drained of their wonder by repeated use, the words' over-familiarity belies their significance:
"the fewer and simpler the connections between modules, the easier it is to understand each module without reference to other modules. minimizing connections between modules also minimises the paths along which changes and errors can propagate into other parts of the system, thus eliminating disastrous, 'ripple effects,' where changes in one part causes errors in another, necessitating additional changes elsewhere, giving rise to new errors, etc."
the paper dashes on, elaborating these points by introducing the concepts of coupling and cohesion - thereby supplying strong contenders for the fourth and fifth greatest encapsulation paragraphs - but the above exemplifies encapsulation performed well and, more interestingly, badly. when faced with poorly-structured source code, we tend to recoil viscerally from the sight of countless dependencies radiating directionlessly throughout the system. still today the ripple-effects identified by messrs stevens et al. cost our industry hundreds of millions of dollars every year which, given the tools furnished by our three papers here, is odd.
none of the papers presented here enjoyed complete originality even on first publication. literary shards presaged all. these passages, however, consolidated - and to a huge degree innovated - key principles by which all good software continues to be built today. their authors deserve recognition as some of computing's finest minds.
concepts evolve. the world for which software was written in the seventies is not the world now outside our windows. perhaps some day software will not be composed of individual, interacting parts and so separation of concerns, information-hiding and ripple-effect will fade from the programmer's vocabulary.
that day, however, is not yet come.
photo credit attribution.
Opinions expressed by DZone contributors are their own.