Jump to content

Abstraction principle (computer programming)

From Wikipedia, the free encyclopedia
This is an old revision of this page, as edited by Pcap (talk | contribs) at 15:11, 25 August 2009 (saving, will add more refs shortly). The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.
(diff) ← Previous revision | Latest revision (diff) | Newer revision → (diff)

In software engineering, the abstraction principle is a basic dictum that aims to reduce code duplication whenever practical. Its origins are uncertain; it has and reinvented a number of times, sometimes under a different name, with slight variations. A generalization of this principle is the "don't repeat yourself" principle, which recommends avoiding the duplication of information in general, and also avoiding the duplication of human effort involved in the software development process.

The principle

In its formulation by Benjamin C. Pierce in Types and Programming Languages (2002), the abstraction principle reads:

Each significant piece of functionality in a program should be implemented in just one place in the source code. Where similar functions are carried out by distinct pieces of code, it is generally beneficial to combine them into one by abstracting out the varying parts.

History

Under this very name, the abstraction principle appears into a long list of books. Here we give a necessarily incomplete list, together with the formulation:

  • Bruce J. MacLennan (1983) Principles of programming languages: design, evaluation, and implementation: "Avoid requiring something to be stated more than once; factor out the recurring pattern".[1]
  • Jon Pearce (1998) Programming and Meta-Programming in Scheme: "Structure and function should be independent".[2]

More recently, the principle has been reinvented in extreme programming under the slogan "Once and Only Once". The definition of this principle was rather succinct in its first appearance: "no code duplication".[3]

Implications

The abstraction principle is often stated in the context of some mechanism intended to facilitate abstraction. Such mechanisms include: abstract data types, type polymorphism, generic programming etc.

Generalizations

"Don't repeat yourself", the "DRY principle", is a generalization developed in the context of multi-tier architectures, where related code is by necessity duplicated to some extent across tiers. It is intended to be obeyed not only in respect to artifacts, such as code, which may need be generated or transformed from a single master source in this context.

References

  1. ^ Bruce J. MacLennan, Principles of programming languages: design, evaluation, and implementation, Holt, Rinehart, and Winston, 1983, p. 53
  2. ^ Jon Pearce, Programming and meta-programming in scheme, Birkhäuser, 1998, ISBN 0387983201, p. 40
  3. ^ Kent