开发者

How to Share Interface Implementation

I am facing a situation in which both the codebehind file of an ASPX master page and that of a regular ASPX page that does not use the master implement an interfance. The implementation is exactly the same.

Is it possible to make the two codebehinds share the implemenation instea开发者_JS百科d of each has its copy of the same implementation? If yes, how should I approach this?

Thank you in advance for any insight.

John


How about using composition, on which both, the Master and the ASPX page have a reference to a class that implements the interface?

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)
    {

    }
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜