Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Inheritance in C#

Posted on 2016-08-19
3
Medium Priority
?
127 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 45

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 35

Accepted Solution

by:
ste5an earned 2000 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

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

Question has a verified solution.

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

In my previous two articles we discussed Binary Serialization (http://www.experts-exchange.com/A_4362.html) and XML Serialization (http://www.experts-exchange.com/A_4425.html). In this article we will try to know more about SOAP (Simple Object Acces…
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.
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…
Please read the paragraph below before following the instructions in the video — there are important caveats in the paragraph that I did not mention in the video. If your PaperPort 12 or PaperPort 14 is failing to start, or crashing, or hanging, …

609 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