Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/xml/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Interface 如何共享接口实现_Interface - Fatal编程技术网

Interface 如何共享接口实现

Interface 如何共享接口实现,interface,Interface,我面临的情况是,ASPX母版页的代码隐藏文件和不使用母版的常规ASPX页的代码隐藏文件都实现了干扰。实现完全相同 有没有可能让两个CodeBehind共享实现,而不是各自拥有相同实现的副本?如果是,我应该如何处理 提前感谢您提供的任何见解 John使用composition怎么样,在composition上,Master和ASPX页面都有一个对实现接口的类的引用 public interface IFace { int MyProperty { get; set; } void

我面临的情况是,ASPX母版页的代码隐藏文件和不使用母版的常规ASPX页的代码隐藏文件都实现了干扰。实现完全相同

有没有可能让两个CodeBehind共享实现,而不是各自拥有相同实现的副本?如果是,我应该如何处理

提前感谢您提供的任何见解


John

使用composition怎么样,在composition上,Master和ASPX页面都有一个对实现接口的类的引用

public interface IFace
{
    int MyProperty { get; set; }
    void MyMethod(string pVariable);
}

[Serializable]
public class ClassA:IFace
{
    public ClassA()
    {

    }

    #region IFace Members

    public int MyProperty
    {
        get
        {
            throw new NotImplementedException();
        }
        set
        {
            throw new NotImplementedException();
        }
    }

    public void MyMethod(string pVariable)
    {
        throw new NotImplementedException();
    }

    #endregion
}

public partial class MasterPage : System.Web.UI.MasterPage
{
    private ClassA IntefaceImplementor = new ClassA();
    protected void Page_Load(object sender, EventArgs e)
    {

    }
}

public partial class _Default : System.Web.UI.Page
{

    private ClassA InterfaceImplementor = new ClassA();
    protected void Page_Load(object sender, EventArgs e)
    {

    }
}