Abstraction principle (programming)
Encyclopedia
In software engineering
Software engineering
Software Engineering is the application of a systematic, disciplined, quantifiable approach to the development, operation, and maintenance of software, and the study of these approaches; that is, the application of engineering to software...

 and programming language theory
Programming language theory
Programming language theory is a branch of computer science that deals with the design, implementation, analysis, characterization, and classification of programming languages and their individual features. It falls within the discipline of computer science, both depending on and affecting...

, the abstraction principle (or the principle of abstraction) is a basic dictum
Dictum
In United States legal terminology, a dictum is a statement of opinion or belief considered authoritative though not binding, because of the authority of the person making it....

 that aims to reduce duplication of information in a program (usually with emphasis on code duplication) whenever practical by making use of abstraction
Abstraction (computer science)
In computer science, abstraction is the process by which data and programs are defined with a representation similar to its pictorial meaning as rooted in the more complex realm of human life and language with their higher need of summarization and categorization , while hiding away the...

s provided by the programming language or software libraries. The principle is sometimes stated as a recommendation to the programmer, but sometimes stated as requirement of the programming language, assuming it is self-understood why abstractions are desirable to use. The origins of the principle are uncertain; it has been reinvented a number of times, sometimes under a different name, with slight variations.

When read as recommendation to the programmer, the abstraction principle can be generalized as the "don't repeat yourself
Don't repeat yourself
In software engineering, Don't Repeat Yourself is a principle of software development aimed at reducing repetition of information of all kinds, especially useful in multi-tier architectures...

" 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

As a recommendation to the programmer, in its formulation by Benjamin C. Pierce
Benjamin C. Pierce
Benjamin Crawford Pierce is an American professor of computer science at the University of Pennsylvania. Pierce joined Penn in 1998 from Indiana University and held research positions at the University of Cambridge and the University of Edinburgh. He received his Ph.D. from Carnegie Mellon...

 in Types and Programming Languages
Types and Programming Languages
Types and Programming Languages, ISBN 0-262-16209-1, is a book by Benjamin C. Pierce on type systems.A review by Frank Pfenning called it "probably the single most important book in the area of programming languages in recent years."...

(2002), the abstraction principle reads (emphasis in original):
As a requirement of the programming language, in its formulation by David A. Schmidt in The structure of typed programming languages (1994), the abstraction principle reads:.

History and variations

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 if it is succinct:
  • Alfred John Cole, Ronald Morrison (1982) An introduction to programming with S-algol: "[Abstraction] when applied to language design is to define all the semantically meaningful syntactic categories in the language and allow an abstraction over them".
  • 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".
  • Jon Pearce (1998) Programming and Meta-Programming in Scheme: "Structure and function should be independent".


The principle plays a central role in design patterns
Design pattern (computer science)
In software engineering, a design pattern is a general reusable solution to a commonly occurring problem within a given context in software design. A design pattern is not a finished design that can be transformed directly into code. It is a description or template for how to solve a problem that...

 in object-oriented programming
Object-oriented programming
Object-oriented programming is a programming paradigm using "objects" – data structures consisting of data fields and methods together with their interactions – to design applications and computer programs. Programming techniques may include features such as data abstraction,...

, although most writings on that topic do not give a name to the principle. The influential book by the Gang of Four, states: "The focus here is encapsulating
Encapsulation (object-oriented programming)
In a programming language encapsulation is used to refer to one of two related but distinct notions, and sometimes to the combination thereof:* A language mechanism for restricting access to some of the object's components....

 the concept that varies
, a theme of many design patterns." This statement has been rephrased by other authors as "Find what varies and encapsulate it."

In this century, the principle has been reinvented in extreme programming
Extreme Programming
Extreme programming is a software development methodology which is intended to improve software quality and responsiveness to changing customer requirements...

 under the slogan "Once and Only Once". The definition of this principle was rather succinct in its first appearance: "no duplicate code". It has later been elaborated as applicable to other issues in software development: "Automate every process that's worth automating. If you find yourself performing a task many times, script it."

Implications

The abstraction principle is often stated in the context of some mechanism intended to facilitate abstraction. The basic mechanism of control abstraction is a function or subroutine
Subroutine
In computer science, a subroutine is a portion of code within a larger program that performs a specific task and is relatively independent of the remaining code....

. Data abstractions include various forms of type polymorphism
Type polymorphism
In computer science, polymorphism is a programming language feature that allows values of different data types to be handled using a uniform interface. The concept of parametric polymorphism applies to both data types and functions...

. More elaborate mechanisms that may combine data and control abstractions include: abstract data type
Abstract data type
In computing, an abstract data type is a mathematical model for a certain class of data structures that have similar behavior; or for certain data types of one or more programming languages that have similar semantics...

s, including classes
Class (computer science)
In object-oriented programming, a class is a construct that is used as a blueprint to create instances of itself – referred to as class instances, class objects, instance objects or simply objects. A class defines constituent members which enable these class instances to have state and behavior...

, polytypism etc. The quest for richer abstractions that allow less duplication in complex scenarios is one of the driving forces in programming language research and design.

Inexperienced programmers may be tempted to introduce too much abstraction in their program—abstraction that won't be used more than once. A complementary principle that emphasize this issue is "You Ain't Gonna Need It
You Ain't Gonna Need It
"You ain't gonna need it" is the principle in extreme programming that programmers should not add functionality until it is necessary...

" and, more generally, the KISS principle
KISS principle
KISS is an acronym for the design principle Keep it simple, Stupid!. Other variations include "keep it simple and stupid", "keep it short and simple", "keep it simple sir", "keep it simple or be stupid" or "keep it simple and straightforward"...

.

Since code is usually subject to revisions, following the abstraction principle may entail refactoring
Refactoring
Code refactoring is "disciplined technique for restructuring an existing body of code, altering its internal structure without changing its external behavior", undertaken in order to improve some of the nonfunctional attributes of the software....

 of code. The effort of rewriting a piece of code generically needs to be amortized against the estimated future benefits of an abstraction. A rule of thumb governing this was devised by Martin Fowler
Martin Fowler
-Online presentations:* at RailsConf 2006* at JAOO 2006* at QCon London 2007 * at QCon London 2008 * at ThoughtWorks Quarterly Technology Briefing, October 2008...

, and popularized as the rule of three
Rule of three (programming)
Rule of three is a code refactoring rule of thumb to decide when a replicated piece of code should be replaced by a new procedure. It states that you are allowed to copy and paste the code once, but that when the same code is replicated three times, it should be extracted into a new procedure...

. It states that if a piece of code is copied more than once, i.e. it would end up having three or more copies, then it needs to be abstracted out.

Generalizations

"Don't repeat yourself
Don't repeat yourself
In software engineering, Don't Repeat Yourself is a principle of software development aimed at reducing repetition of information of all kinds, especially useful in multi-tier architectures...

", or 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, usually in different languages. In practical terms, the recommendation here is to rely on automated tools, like code generators and data transformation
Data transformation
In metadata and data warehouse, a data transformation converts data from a source data format into destination data.Data transformation can be divided into two steps:...

s to avoid repetition.
The source of this article is wikipedia, the free encyclopedia.  The text of this article is licensed under the GFDL.
 
x
OK