How to use a class as the base, but hide the class type publically?
        Posted  
        
            by James
        on Stack Overflow
        
        See other posts from Stack Overflow
        
            or by James
        
        
        
        Published on 2010-04-30T08:43:41Z
        Indexed on 
            2010/04/30
            8:47 UTC
        
        
        Read the original article
        Hit count: 226
        
c#
I am currently just exposing the properties through a generic interface e.g.
public interface IBaseClass
{
    int ID { get; set; }
}
internal class MyBaseClass : IBaseClass
{
    public MyBaseClass() { }
    public int ID { get; set; }
}
public class MyExposedClass : IBaseClass
{
    private MyBaseClass _base = new MyBaseClass();
    public int ID
    {
        get { return _base.ID; }
        set { _base.ID = value; }
    }
}
Then in my main application I can do:
IBaseClass c = new MyExposedClass();
c.ID = 12345;
But can't do:
MyBaseClass b = new MyBaseClass();
This is my desired behaviour.
However, I was just wondering if this is the correct approach? Or if there was a better way?
© Stack Overflow or respective owner