Solved

Inheritance in C#

Posted on 2016-08-19
3
110 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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 34

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

Business Impact of IT Communications

What are the business impacts of how well businesses communicate during an IT incident? Targeting, speed, and transparency all matter. Find out more in this infographic.

Question has a verified solution.

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

Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
In this video, viewers are given an introduction to using the Windows 10 Snipping Tool, how to quickly locate it when it's needed and also how make it always available with a single click of a mouse button, by pinning it to the Desktop Task Bar. Int…
NetCrunch network monitor is a highly extensive platform for network monitoring and alert generation. In this video you'll see a live demo of NetCrunch with most notable features explained in a walk-through manner. You'll also get to know the philos…

689 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