Solved

Inheritance in C#

Posted on 2016-08-19
3
94 Views
Last Modified: 2016-08-24
I have an abstract class called 'BasePage'.
And many other classes inherit from this class.
For example, LoginPage class inherit from 'BasePage' class.

class LoginPage:BasePage{
...
}
class EmployeePage:BasePage{
...
}

Open in new window


And BasePage class inherits from 'Base' class.
And Base class has a property of 'BasePage' type.
I don't understand what this is good for.

Why don't we add CurrentPage property into 'BasePage' class?
Can you explain the intention of adding 'BasePage' type property to 'Base' class and 'BasePage' inherits from 'Base' class?
public class Base
{
        public BasePage CurrentPage { get; set; }
 }

Open in new window


Then, in a UnitTest1 class, it is used as follow:
  public class UnitTest1 : Base
    {
        string url = "http://localhost";        


        [TestMethod]
        public void TestMethod1()
        {        
            .....    
            LoginPage page = new LoginPage();
            ......
            CurrentPage = page.ClickEmployeeList();            
            ((EmployeePage)CurrentPage).ClickCreateNew();
        }
    }

Open in new window

0
Comment
Question by:Isabell
3 Comments
 
LVL 44

Expert Comment

by:AndyAinscow
ID: 41763734
Why it is done this way you would have to ask the original designer/coder.  Everything else is just a guess.

>>Why don't we add CurrentPage property into 'BasePage' class?
Very good question.  The current layout looks rather strange to me with the base class having to 'know' about a derived class for it to function.
0
 
LVL 33

Accepted Solution

by:
ste5an earned 500 total points
ID: 41764218
Just a wild guess:

It's kind of a context concept. So that you don't have to call a different objects to get the current page.
0
 

Author Closing Comment

by:Isabell
ID: 41768533
Thanks ste5an
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
This article aims to explain the working of CircularLogArchiver. This tool was designed to solve the buildup of log file in cases where systems do not support circular logging or where circular logging is not enabled
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

861 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question