?
Solved

Inheritance in C#

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

On Demand Webinar: Networking for the Cloud Era

Ready to improve network connectivity? Watch this webinar to learn how SD-WANs and a one-click instant connect tool can boost provisions, deployment, and management of your cloud connection.

Question has a verified solution.

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

For those of you who don't follow the news, or just happen to live under rocks, Microsoft Research released a beta SDK (http://www.microsoft.com/en-us/download/details.aspx?id=27876) for the Xbox 360 Kinect. If you don't know what a Kinect is (http:…
This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
In this video we outline the Physical Segments view of NetCrunch network monitor. By following this brief how-to video, you will be able to learn how NetCrunch visualizes your network, how granular is the information collected, as well as where to f…
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…
Suggested Courses

777 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