REST Assured Tutorial 5 – Abstraction – Hide The Implementation

As a part of End to End REST Assured Tutorial , in this post We will learn about Abstraction in Java.

If you are thinking why this topic is necessary , do not worry. I will connect all dots in upcoming posts.

Abstraction is one of the pillar in Object Oriented Programming. Java is an Object Oriented Programming language so it follows abstraction concept is as well. You must have gone through Abstraction concept and you find a common sentence as below:-

Hiding the implementation and showing the essential feature to user is called Abstraction. Abstraction can be achieved using Abstract class and interface.”

When you start learning about Abstract class and interface and try to relate above Abstraction concept with it, you lose the path. When we say hiding the implementation is an abstraction then a method is also an example of abstraction. You create a method with all logic in it to perform a task and make it public so that other can simply use it without bothering about how method works internally. “Showing all essential details to outside world” is also possible using access specifiers like public , private , protected and default. What is special in Abstract class and Interface which allow us to achieve Abstraction? I hope I am making some sense.

I can define Abstraction as “Hiding the implementation” which could be done in multiple ways.

When we say Abstract class and Interface are ways to achieve abstraction, it means that “Perform a specific task and I don’t really bother how you do it“. Suppose I need to get the population of each district in India. I have a token which says that I need population details. Now a representative of each district will come to me and collect token. It is all representatives responsibility to provide me population detail of their districts. I really don’t bother how they will arrange the details. Process of performing tasks may be different for each district. This is actually meant by Abstraction.

Now relate this understanding with the concepts of Interface and Abstract class. Hopefully you will be able to understand. The best example will be WebDriver interface in Selenium. WebDriver has a contract of methods which is supposed to perform a specific task. Browser specific classes which implement WebDriver has responsibility to perform those tasks in their ways. Chrome browser does not worry about how Firefox browser is performing a tasks. WebDriver also has nothing to worry about implementation done by various browser. This is Abstraction.

If you have any doubt, feel free to comment below.
If you like my posts, please like, comment, share and subscribe.

You can find all Selenium related post here.
You can find all API manual and automation related posts here.
You can find frequently asked Java Programs here.

2 thoughts on “REST Assured Tutorial 5 – Abstraction – Hide The Implementation

  1. The example of selenium driver is really good.

    Driver drv = new ChromeDriver();
    Driver drv = new FirefoxDriver();

    so drv.get() will have their own implementation of chrome and firefox

  2. very well explained the concept of Abstraction ,, but one doubt is

    if the concept is i dont care how you implement it.. then they can use public private etc whataver they want ?

    Why those keywords explicitly mentioned ? We don’t use them to achieve abstraction generally

    we use abstract class and interface instead of those access specifiers.

Leave a Reply

Your email address will not be published. Required fields are marked *