Solved

Inheritance in C#

Posted on 2016-08-19
3
69 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 32

Accepted Solution

by:
Stefan Hoffmann 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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Recently while returning home from work my wife (another .NET developer) was murmuring something. On further poking she said that she has been assigned a task where she has to serialize and deserialize objects and she is afraid of serialization. Wha…
This article describes relatively difficult and non-obvious issues that are likely to arise when creating COM class in Visual Studio and deploying it by professional MSI-authoring tools. It is assumed that the reader is already familiar with the cla…
This tutorial demonstrates a quick way of adding group price to multiple Magento products.
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

708 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now