8

I'm learning about OOP and Java, and the definition of Abstraction is the process of hiding the implementation details from the user, only the functionality will be provided to the user.

Can someone explain me what is the difference between functionality and implementation details?

  • Possible duplicate of [How does abstraction helps in hiding the implementation details in Java?](https://stackoverflow.com/questions/46041202/how-does-abstraction-helps-in-hiding-the-implementation-details-in-java) – Lino Feb 21 '19 at 08:52
  • Maybe even better dupe: https://stackoverflow.com/questions/24626/abstraction-vs-information-hiding-vs-encapsulation – Lino Feb 21 '19 at 08:52
  • Don't think too much about these definitions. "abstraction", "details" and "functionality" are used because they still have their ordinary meaning you'll find in a dictionary. There's no exact meaning in programming for them. It's a concept that has slightly different meaning to everyone. What people try to say with "abstraction" is that you don't go into details (like what kind of for/while loop you'll use), you keep it at a conceptual level. An "implementation detail" is always whatever you *feel* is too much detail to describe the concept. The same thing might be a concept in other places. – zapl Feb 21 '19 at 09:04

5 Answers5

11

Real world example: Think of a gear box, the user only have the ability to change gears and that is the functionality.

The mechanism behind the gearbox and how the gear box is working internally is the implementation and the implementation is hidden from the user.

Fakhar Ahmad Rasul
  • 1,595
  • 1
  • 19
  • 37
5

A good example is the Java List interface.

That provides methods to dynamically add or remove elements to the list. That is the function. How that really happens is not expressed in that interface, and for users of that List interface, it also doesn't matter (too much).

For example, the implementation could be a doubly linked list, where you just change the "links" between the objects in your list, or if an array is used that needs to grow/shrink accordingly, that is up to the implementation) Of course, there are actual pros and cons for the different implementation options, but in many situations, you might decide to not care about them.

GhostCat
  • 137,827
  • 25
  • 176
  • 248
3

Functionnality : What it does

Implementation : How it does it

vincrichaud
  • 2,218
  • 17
  • 34
2

Encapsulation: wrapping up of data into a single unit.single unit(class). within a class, there are members, data members which wrapped in a unit called class. For example, your bag is a single unit you put books, pens inside the bag. The same class is a single unit.

Resources for Encapsulation:

Abstraction: hiding the background details. OOP provides these facilities. we can keep data inside the objects which provide security. The class also provide this facility you cannot access private data of the class. Only public, protected data can be accessible if you want to secure your data when you make it private.

Resources for Abstraction:

halfer
  • 19,824
  • 17
  • 99
  • 186
dpapadopoulos
  • 1,834
  • 5
  • 23
  • 34
1

To put it simply, consider the code below:

public Data getStoredData(int ID) {
    DBConnection conn = DBConnection.getInstance();
    conn.connect();

    Data data = conn.query("..." + ID);

    if(data != null) {
        data.setSomeValue('Some Value');
    }

    return data;
}

The term implementation details are the code you write inside your function.

The term functionality it the method signature or the things you want to expose to the calling client. This is how you want your method to be used.


In the example above, the functionality is this public Data getStoredData(int ID), while your implementation is the one that resides inside it.

arjayosma
  • 540
  • 3
  • 15