Abstraction principle (computer programming)
![]() | This article or section is in a state of significant expansion or restructuring. You are welcome to assist in its construction by editing it as well. If this article or section has not been edited in several days, please remove this template. If you are the editor who added this template and you are actively editing, please be sure to replace this template with {{in use}} during the active editing session. Click on the link for template parameters to use.
This article was last edited by Pcap (talk | contribs) 15 years ago. (Update timer) |
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.