6

I need a very simple explanation because I'm not a professional programmer.

I found the terminology "abstraction layer" reading the documentation of mysqli extension where is described the difference among mysql, mysqli and PDO extensions in PHP. The article is this, that's where I met "abstraction layer" for the first time (referred to PDO).

Now, trying to elaborate my question, we could speak of PDO abstraction layer against mysqli extension in php. So, for example, why mysqli is not defined as abstraction layer? How an abstraction layer acts? (like PDO in php)

I would like to understand in a general way what is an"abstraction layer", I will not do particular questions about php or mysqli and PDO extensions.

So, what is an abstraction layer? And what is its difference from a common application's extension?

  • 4
    It's a layer that abstracts underlying functionality. Can you elaborate on what exactly is causing your confusion? Perhaps by quoting some articles? – Jeroen Vannevel Jan 12 '14 at 17:31
  • 2
    @JeroenVannevel the only article I can post is this, that's where I met "abstraction layer" for the first time (referred to PDO). Now, trying to elaborate my question, we could speak of PDO abstraction layer against mysqli extension in php. So, for example, why mysqli is not defined as abstraction layer? How an abstraction layer acts? (like PDO in php) – marco Jan 12 '14 at 18:02
  • 1
    @JeroenVannevel If you should represent an abstraction layer with an image (or a metaphor) what would be your image? You know, sometimes we can use images to figure a concept (for example, in a program language we see a variable like a box, an array like a set of box, and so on), sometimes it helps... – marco Jan 12 '14 at 18:09
  • I watched some introductory level videos on YouTube last night and one addressed this. It's here youtube.com/watch?v=p7nGcY73epw. Check out their other stuff, nice explanations. – user1248 Jan 12 '14 at 18:13
10

Often an abstraction layer is commonly used to 'abstract' away detail.

Say you had a program for moving money around between different banks. There is a function for moving money to BankA, and a different function for moving money to BankB and so on. The different functions might exist because the information that different banks request varies (As a simple example maybe one requests the senders first name and surname, and another requests the senders first initial and surname).

Your functions might be:

MoveMoneyToBankA(amount, accountNo, senderFirstName, senderSurname)
{
   ... Code to move money to bank A
}

MoveMoneyToBankB(amount, accountNo, senderFirstInitial, senderSurname)
{
   ... Code to move money to bank A
}

To abstract away all the different things a program needs to think about when communicating with different banks, an abstration layer might be implemented by adding the function 'MoveMoneyToBank'

MoveMoneyToBank(amount, accountNo, senderFirstName, senderSurname, bankName)
{
   ... If bank name = 'BankA' call MoveMoneyToBankA

   ... If bank name = 'BankB', find senderFirstInitial using senderFirstName, and call 'MoveMoneyToBankB'
}

So what you have done here is abstracted away the detail that needs to be managed when communicating with two different banks. A programmer can now just use the general MoveMoneyToBank function, and not have to think about the different requirements of each bank.

In reality, this might not just be functions with in the same program, but even different projects within the same solution, or a new software project that draws in lots of components and deals with the complexity of working with all the separate components to achieve a common goal.

2

Generally, an abstraction layer is an API (set of functions) which is hiding the underlying implementation/complexity. The purpose is to provide a clear and easier-to-use interface over an existing set of functionality.

Imagine you want to create a stack using a list. You could build a class called Stack. You'd have a private list inside it to store the elements. You'd also have methods to push and pop elements from the stack. This class is an abstraction layer over list representing a stack. It hides the implementation (how elements are stored, how they are pushed and popped) and provides a simple interface to work with a stack.

The wikipedia article about abstraction layers is a good starting point.

Regarding database abstration layers. For example, you have a MySQL database and you want to access it from your PHP program. An abstraction layer in this case would provide the funtionality of opening connetion to the database, executing queries, calling stored procedures, etc. So when working with the database from PHP code, you won't have to think about how connection is actually created or how MySQL queries are actually passed to the database, executed there and how the result is returned and parsed.

2

I think that under most circumstances, an abstraction layer serves as a simplification or gateway to a more complicated underlying layer.

Suppose you have a database layer that allows you to perform nearly all database operations you can imagine. However, such a layer or API would be fairly complicated to use due to its number of features. Especially if you just want to do something simple.

In this case, an abstraction layer might be available that only provides a subset of the functionalities in an easier to use fashion. While still using the underlying layer, this layer could then provide more intuitively named methods/functions, easier to use parameters and/or predefined parameters that should help you get started...

Often times, such abstraction layers also introduce more general or real world concepts that are more easily understood by people that are no domain experts. (To give a technical example: the database layer could return you a resultset that needs to be iterated, while the abstraction could return you a list of well defined objects that are ready to be used)

While such underlying layers provide greater functionality, they usually require more time to get something done if you are not yet familiar with it.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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