polymorphism in framework code example
Example 1: where do you use overloading in framework
Method overloading is providing
two separate methods in a class
with the same name but different arguments,
while the method return type
may or may not be different, which
allows us to reuse the same method name.
In my framework==
I use implicit wait in Selenium. Implicit wait
is an example of overloading. In Implicit wait
we use different time stamps such as SECONDS, MINUTES, HOURS etc.,
A class having multiple methods with
same name but different parameters
is called Method Overloading
Example 2: polymorphism in framework
HOW DO YOU IMPLEMENT POLYMORPHISM IN YOUR FRAMEWORK
Set<Integer> set1 = new HashSet<>();
Map<Integer> set2 = new HashMap<>();
List<Integer> mySet = new ArrayList<>();
JavaScriptExecuter js = (JavaScriptExecuter)Driver.getDriver;
TakeScreenshot screen = (TakeScreenshot)Driver.getDriver;
WebDriver driver = new ChromeDriver();
WebDriver driver = new FirefoxDriver();
AppiumDriver driver = new AndroidDriver();
Example 3: where do you use overriding in framework
Set<Integer> set = new HashSet<>();
List<Integer> list = new ArrayList<>();
set.add(4); ==> HashSet overrides add() method from Collection Interface
list.add(8); ==> ArrayList overrides add() method from Collection Interface
WebDriver driver1 = new ChromeDriver();
driver1.get("xxxxxx"); ChromeDriver overrides get/findElement/etc.
methods from WebDriver Interface.
WebDriver driver2 = new FirefoxDriver();
driver2.get("xxxxxx"); FirefoxDriver overrides
get/findElement/etc. methods from WebDriver Interface.