Function Overloading

Function Overloading in Automation

Reading Time: 2 minutes

OOPS concepts are important to learn for Software Engineers.

I have posted this picture on Linkedin few days back, but this post is a detailed one, covering more of it. (Feel free to comment over there on linkedin if you have any views

In this post i have tried to simplify the concept of function overloading which will help you to remember it easily.

When you have a function with the same name but different arguments, you have overloaded the function.

In this picture you see, call method is called once with single parameter and the other with 2 parameters.

call(“mummy”);

call(“mummy”,”ji”);

So based on the number of parameters, the system will know which one to call.

Indian can relate to this better as its cultural thing. We call our mom. Mummy and our in mother-in-law with salutation(Ji) – Not a universal truth. So please don’t be offended.

Other programming examples

It would be when you need to calculate the area. If its a square you need 1 parameter, if rectangle then 2 parameters.

Area for a square = (side)^2   – Single Parameter

Area for a rectangle = length * width – Multiple Parameter

 

Function Overloading
Function Overloading in Automation

Examples in Automation 

  • When you define your own wrapper methods. lets say you must add a Web driver wait, to wait for visibility of element for 10 seconds generally. But there is an element which takes more than 20 seconds.

    wait(); wait(30);

    So the first one will wait for a default time out (10 seconds), and you have defined another method which takes the time from user. There could be some places where you might want to wait more so that method will take the input from the user.

  • You can define your own find Element Wrappers

driver.findElementWith(By) / driver.findElementWith(String)

  • While doing API automation you can overload HTTP verbs like GET() , GET(headerparams) based on your requirement.

In this case also the method name remains the same, but arguments are different.

What’s the advantage

  • You can keep the same logical names and need not remember all of them like findElementWithBy, findElementWithText. System can decide this based on type and number of arguments you have passed. you can simply call findElementWith
Function Overloading In Java
Function Overloading In Java

Hope you liked it, if you want me to make more such memes, do subscribe and i have created the page on Instagram as well, do connect there as well.

Share any ideas you want me to cover if any mistakes happy to correct, bit.ly/khuranagaurav ( youtube / insta)

 

Related Posts

2 thoughts on “Function Overloading in Automation

    1. Hi Renuka, Thank you for taking to read through this. Wrapper methods we create generally in framework to make the work of people using it easy.

      For example in automation , for findinganelement you can find by just passing text, by just passing By or by passing a webelement. So you can create 3 methods.

      All methods will have the same name findelement but parameters would be different ( by , text , webElement) , so its function overloading used in a good way.
      findElementsBy(by) / findElementsBy(text) / findElementBy(Webelement)

      so for you its one name, findElementsBy. So you have wrapper findElement function of selenium via creating 3 methods findElementsBy

Leave a Reply

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