Object Oriented Programming Glimpse
An approach to building applications by focusing on objects that interact with one another
Features of objected oriented programming
1. Flexible
2. Natural
3. Reuse of code
4. Testable
In this course, we will be using C# as our object-oriented programming language.
C# is a simple, modern, general-purpose, object-oriented programming language developed by Microsoft
Now we talk about some main topics/concepts or building blocks of object-oriented programming
Classes and object
- Classes are the blueprint for objects
- Objects are an instance of a class
Now that sounds like definitions, good to say during interviews 😜
Well to make more sense and to get the real essence of this definition we will do some object-oriented programming.
Consider you got a new project or client request is to build an automation framework for web application.For now, we focus on the Driver module which is responsible for managing your browser(Start, Close etc.)
We are not going to build full-fledged test automation framework now, we will cover that later in the course, however, I will walk through all the stages of the project which will make the oops concept more clear.
Now you must be wondering, I am here to learn automation and not to build any product and how oops concept will help in automation learning.
Well automation framework itself is a product altogether and to build such a product you need to know the basics of object-oriented programming.
Let's start
Now coming back to the client request, how should you start building the framework(Driver Module).
Below are the stages which will help you to solve the problem in oops way.
Here the requirement is to build a module that is responsible for managing browser, simple enough.
Now how does browser behave or which all functionality is needed during our script execution
- Starting the browser(Loading configurations, Reading browser type from a config file or user input etc)?
- Stopping the browser(Closing browser, clearing cache etc)?
- There should be a way for other modules to use this module for communication with the browser.
There can be many more however, these requirements are enough to start
Identifying Classes
Now we are clear about what we need to build, we will identify classes for our system
We will try to share the behavior of application into multiple related classes rather than one very large class.
Basically, each class should have a single responsibility which is called SRP(Single responsibility principle), we will talk about this in later lectures
UML Diagrams are mostly used to visualize the design of a system.
Below is the initial sketch for DriverManager class
We have also added Launch, Quit and GetDriver Methods.
So we can call our class as a specification for a set of data and operations that act on data.
Finding the Relation between classes
As discussed earlier we will be using the DriverMangaer class in our Page class. Here you can think of page class as a class which holds details of a page.
Example – Google homepage class holds details like search Button, Cancel button, Search String etc.
A single class will not be able to solve a business problem, its mostly multiple related classes each one having single responsibility help to solve the business problem.
Below is our class diagram now
Here PageClass gets the driver object using the GetDriver Method of DriverManager and uses it to perform its tasks. This was simple 😊
This way we are going to add more classes and establish a relation between them to solve the problem statement.
Building Reusable common code
As you started adding more code to solve the business problem you will find that you are repeating the same code again and again, that's alarming and time to stop coding and think if you can refactor it?
Sounds like a design principle 🙆
Yes. you got it right we are talking about another design principle here call DRY (Don't repeat yourself )
In simple words, it states that a particular common logic should be represented once in an application.
"Repetition is the root of all software evil."
-Unknown
We will revisit this topic later in the course, however, the motive was to give you a glimpse of OOP.
In the Next lecture, we will cover some C# basics(Veg/ Non-Veg starters/appetizer of our learning path )
In the Next lecture, we will cover some C# basics(Veg/ Non-Veg starters/appetizer of our learning path )
Comments
Post a Comment