Search code examples
javaoopinterfaceabstraction

Can abstraction be achieved using interfaces


In OOP, abstraction is when we only make useful details available to the user and hide all the implementation details. So, if I have an interface and I implement it in a class then how is this achieving abstraction? I read this article about "how to achieve 100% abstraction using interfaces"

If the question sounds off topic or vague then it really is, all I want to know is how is abstraction in oop related to interfaces.


Solution

  • So, if I have an interface and I implement it in a class then how is this achieving abstraction?

    Because other code can use that interface without knowing how exactly it is implemented. You can even get to the point where the "client" code using the interface has absolutely no idea which class exactly was instantiated.

    Meaning: your write code that uses List<T>, and that means you really don't think whether that list is actually an ArrayList or WhatEverElseList.