1I used in defining a common super class while writing POM layer of the framework
2We usually create an abstract class named
3BasePage to have all common members for every page written
4in this class like getPageTitle().
5Then each Page class (HomePage, LoginPage, DashboardPage
6etc.) inherit from BasePage.
7Sometimes one may need to change the behavior of methods
8implemented in superclass. So, subclass has freedom to
9override that method where we use polymorphism.
10This is how we use Abstract class in real projects.
1I have created my PageBase class as super
2class of the all page classes.
3I have collected all common elements
4and functions into PageBase class and
5all other page classes extent PageBase class.
6By doing so, I don't have to locate very
7common WebElements and it provides
8reusability in my framework.
9
10I have implement abstraction in my POJO
11classes for API Testing. My POJO classes
12implements Comparable interface and
13I override the compareTo() abstract method.
14
15These concepts are commonly used in
16 framework development. Abstract class
17 is used in defining a common super
18class while writing Page Object Model
19layer of the framework. We usually create
20an abstract class named PageBase to have
21all common members for every page written
22in this class for example getPageTitle().
23Then each Page class
24 (HomePage, LoginPage, DashboardPage etc.)
25inherit from BasePage. Sometimes one
26may need to change the behavior of
27methods implemented in superclass.
28So, subclass has freedom to override
29that method where we use polymorphism.
30This is how we use Abstract class in projects.
31
1OOP focuses on the objects that are
2required to be manipulated instead of logic.
3- It makes development and maintenance easier
4- It provides data hiding
5- It provides ability to simulate real-world
6- less memory and organized
7- reusable
8
9OOP language follow 4 principles:
101-ENCAPSULATION: We can hide direct access
11to data by using private key and we can access
12private data by using getter and
13setter method. in my framework I have POJO
14class which I use it when we need to represent
15some data as Java object. So to that we need to
16create a Java class to represent it's data.
17So in POJO class I use encapsulation and
18getter setter method to access them.
19
202-ABSTRACTION: It is a process of hiding
21implementation details and showing only
22functionality to the user. Abstraction lets
23you focus on what the object does instead of how it does it.
24In my framework I have created my
25PageBase class as super
26class of the all page classes.
27I have collected all common elements
28and functions into PageBase class and
29all other page classes extent PageBase class.
30By doing so, I don't have to locate very
31common WebElements and it provides
32reusability in my framework.
33
343-INHERITANCE: It is used to define the
35relationship between two classes. When a
36child class acquires all properties and
37behaviors of parent class known as inheritance.
38Child class can reuse all the codes written
39in parent class. It provides the code
40reusability. in my framework I have
41a TestBase class which I store
42all my reusable code and methods.
43My test execution classes and
44elements classes will extend the
45TestBase in order to reuse the code.
46
474-: POLYMORPHISM: It is an ability of object
48to behave in multiple form. The most common use
49of polymorphism is Java, when a parent class reference
50type of variable is used to refer to a child
51class object.
52I use polymorphis almost everywhere
53It is an ability of object to behave in multiple
54form. The most common use of polymorphism is Java, when a
55parent class reference type of variable
56is used to refer to a child class object.
57E.g.: WebDriver driver = new ChromeDriver();
58JavaScriptExecuter js = (JavaScriptExecuter)Driver.getDriver;
59TakeScreenshot screen = (TakeScreenshot)Driver.getDriver;
60WebDriver driver = new ChromeDriver();
61
62
63
64