Take the 2-minute tour ×
Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. It's 100% free, no registration required.

I am not sure if both terms can be used interchangeably. Maybe there is some academic distinction in computer science which is not relevant for day-to-day programming? Or can I use both term interchangeably without being wrong? Maybe it depends on the context in which I use both terms?

Edit: On reason why I find both terms possibly interchangeable is a Wikipedia entry about Abstraction layer. There you can find David Wheelers quote 'All problems in computer science can be solved by another level of indirection.'

share|improve this question
4  
...except the problem of too many levels of indirection! –  Mason Wheeler Sep 30 '11 at 21:44
    
@MasonWheeler: You could add another, less indirect level of indirection… –  Jon Purdy Oct 1 '11 at 1:07
    
C++ allows you to add a layer of abstraction without a layer of indirection, so they can't mean the same. –  FredOverflow Oct 1 '11 at 18:23

6 Answers 6

up vote 13 down vote accepted
+50

Abstraction deals with simplification, indirection deals with location.

  • Abstraction is a mechanism that "hides" complicated details of a object in terms of simpler, easier to manipulate terms. In programming, a good example is the difference in details between machine code and the various tools for creating applications that are ultimately based on machine code. Consider creating a Windows Form application with the Visual Studio IDE. The IDE lets you think of the application in terms of easy-to-manipulate items in a What-You-See-Is-What-You-Get manner. The position of a screen widget is abstracted out to a visual location in a frame which you can change by dragging the widget around. Internally, the IDE manipulates the widget using another layer of abstraction such as a high level language (such as C#). C# itself is not manipulated using machine code, it is manipulated using a "Common Runtime Environment" which itself is an abstraction of a computer and operating system.

  • Indirection refers to making the location of an item transparent. If you know a web resource's URI, you can access the resource without knowing its precise location. You do not access the resource directly, instead you access through a channel that passes your request through a series of servers, applications and routers. Indirection may be considered to be a special type of abstraction where the location is abstracted.

share|improve this answer
1  
+1 best answer so far ! Was about to write one but this one is close enough to what I had in mind. –  Newtopian Oct 10 '11 at 2:06

Abstractions are implemented using indirection.

For example, virtual memory: The abstraction is a contiguous address space entirely at your disposal. This abstraction is implemented using indirection via a page table. Instead of directly accessing physical memory addresses, they are translated from a virtual address to a physical address.

To add a layer of abstraction, you have to add a layer of indirection. But adding indirection doesn't necessarily give you an abstraction. For example, having getters and setters on every single variable is a layer of indirection, but if all they do is get and set simple values there is no abstraction.

share|improve this answer
2  
In fact, the last example is not very good. Plain getters and setters do add abstraction. The only one knowing, they are plain, is the class declaring them. If you decide to change the implementation, any code built against the abstraction is not affected. –  back2dos Oct 5 '11 at 14:08
    
can you give any better example which is indirection but not abastraction ? –  Mr Coder Oct 6 '11 at 11:12
    
definitely a wrong example –  Morg. Oct 6 '11 at 11:43
3  
Who said anything about classes? I also said nothing about changing the visibility of a variable. Nothing is stopping you from accessing it directly; it's a variable. But you can also do it with a level of indirection via the getter and setter. Since the semantics of using the getter and setter are the same as accessing the variable directly, there is no abstraction. –  Austin Oct 6 '11 at 15:20
1  
Except that the getter and setter don't necessarily 'just' access the variable. If you are using a getter and setter you are adding an abstraction as you could change them to use a different variable without the user being aware of it, therefore an abstraction. –  DominicMcDonnell Oct 7 '11 at 3:30

Layer of Abstraction and Level of Indirection are distinct concepts. Abstraction is the aggregation and meaningful naming of a number of elements such as pieces of data or program instructions, for instance the concept of a file or method call, whereas indirection is the decoupling of entities to facilitate the postponement of the realisation of their relationship, for example, the use of JNDI to separate the identification of a resource within a program from the actual resource which may eventually be provided by an application container.

Frequently the concepts go hand in hand and which one applies to a particular construct depends on what exercise or discussion is in progress. For instance, the abstract nature of an interface is important when learning or documenting an API; its property of indirection is important when adding extensibility to or creating tests for an application.

A layer of abstraction is the aggregation of abstractions and giving them a conceptual integrity and consistency of usage. CreateProcess is the win32 API name for a bunch of code that builds and executes a process. The "name" is significant to this context because if we called the function something like DoAllocMemThenMakeEnvThenFindEntryPoint... it really would not be very abstract. A layer such as the Win32 API provides a barrier across which a programmer may be advised not to venture. It removes complexity from the caller's viewpoint at the cost of reduced power (flexibility, performance etc). This trade-off is highlighted by frequent discussion of leaky abstractions: we may still need to make direct SQL calls when using Hibernate or make Win32 calls when using .NET.

Regarding indirection, most non-trivial programs operate with some form of user coded indirection, witness COBOL's INPUT-OUTPUT section from before the ark. When accessing a resource such as a database we may see the embedding of a JDBC connection string in the code as Level 0 indirection, a JNDI connection (which delegates the choice of resource to an application container) as Level 1 and some Spring construct that maps the application JNDI identifier to one of many container resources as Level 2. Multiple levels allow a number of parties external to the relationship (in this case a relationship between executing code and a database) to manipulate that relationship. This applies equally to internal program components such as interfaces and events.

We see that, no matter what their other qualities, abstraction reduces complexity whereas indirection increases it. Abstraction reduces power whereas indirection increases it. Indirection can be used to restore the power of abstraction by allowing default behaviour to be overridden by custom callbacks.

share|improve this answer

My understanding is that abstraction mostly refers to functions and indirection mostly refers to data. In other words, the level of abstraction is how deep your stack trace gets, and the level of indirection is how many pointers you have to dereference. At least that's how I use the terms.

share|improve this answer

First, lets try proper definitions for the terms:

  1. Layer of abstraction means:

     a) there is large number of positions which use abstraction
          (layer = all the positions together)
     b) each position is hiding some complex stuff, but allows invoking it 
          using only simple code. 
         (abstraction == one-to-one mapping between simple code and complex code)
    
  2. Level of indirection on the other hand means:

      a) you're counting levels
      b) indirection==there are several steps before you can reach or access the data
      c) level of indirection is just how many steps it takes to access the data
    

Both of these things can mean the same thing, as long as you use:

  a) step = going from simple code to complex code. 
share|improve this answer

A good example of abstraction is calling a single method to store an item in a database. The method abstracts the details of connecting and calling the database. Where an example of indirection is using a struct to access interrupts. You are still accessing the interrupt when you set values in the struct. it is just indirectly through the struct by giving struct member names to specific points in memory.

So abstraction hides details of implementation where indirection simply provides an "indirect" interface through which to access something.

Abstraction is when you do not need to understand what is being hidden, where with indirection you do.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.