我不能继承其他类的网页类吗? [英] Can't I able to inherit the web page class from the other class?

查看:75
本文介绍了我不能继承其他类的网页类吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经宣布了一个网页。我已经定义了所有方法。我现在已经将这些类分开,以便轻松进行测试。我已经声明了另外一个存储库类来执行crud操作。而不是在

I have declared one web page. there I have defined all the methods. I have separated the classes now to do testing easy. I have declared one more repository class to do crud operations. Instead of defining one all the methods of web page class one more time in the

repository class. Is that possible? it is working fine for me. But , I have a doubt here? Can you please somebody help me on this?

What I have tried:

Webpage class:
public partial class MSNBulkImport : System.Web.UI.Page
{

private IFactoryForMSN moqobj = null;

        public MSNBulkImport()
        {

        }

        public MSNBulkImport(IFactoryForMSN moqobj)
        {
            this.moqobj = moqobj;
        }

//Save the data in database.
        public bool InsertBulkImportPortfolios(MSNBulkImportPortfolioTVP mSNBulkImportPortfolioTVP, string updatedBy)
        {
            MSNRepository mSNRepository = new MSNRepository();
            return mSNRepository.InsertBulkImportPortfoliosToDatabase(mSNBulkImportPortfolioTVP, updatedBy);
        }
}

Interface:

<pre>public interface IFactoryForMSN
    {
        
        bool InsertBulkImportPortfoliosToDatabase(MSNBulkImportPortfolioTVP mSNBulkImportPortfolioTVP, string updatedBy);
    }

Repository Class:
Here i am inheriting the webpage. Is that correct? 

public class MSNRepository : MSNBulkImport,IFactoryForMSN 
    {
}

推荐答案

是,但你继承的类必须最终来自 System.Web.UI.Page



编辑==================================


$ b $我知道你想要什么。您不需要界面。您所要做的就是使基类中的所有方法都是虚拟的,这样您就可以在派生类中覆盖它们。请参阅粗体/斜体/带下划线的文字。



Yes, but the class you inherit from has to be ultimately derived from System.Web.UI.Page.

EDIT==================================

I thk I see what you want. You don't need an interface. All you have to do is make all the methods in your base class virtual so you can override them in derived classes. See the bold/italic/underlined text.

public partial class MSNBulkImport : System.Web.UI.Page
{
    private IFactoryForMSN moqobj = null;

    public MSNBulkImport()
    {
    }

    public MSNBulkImport(IFactoryForMSN moqobj)
    {
        this.moqobj = moqobj;
    }

    //Save the data in database.
    public virtual bool InsertBulkImportPortfolios(MSNBulkImportPortfolioTVP tvp, string updatedBy)
    {
        MSNRepository mSNRepository = new MSNRepository();
        return mSNRepository.InsertBulkImportPortfoliosToDatabase(tvp, updatedBy);
    }
}

//Repository Class:
public class MSNRepository : MSNBulkImport
{
    public override bool InsertBulkImportPortfolios(MSNBulkImportPortfolioTVP tvp, string updatedBy)
}


这篇关于我不能继承其他类的网页类吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆