Skip to main content
GameDev.net gamedev.net
🔒 Locked

[.net] Generic and polymorph?

Started by Riddle Jan 24, 2005 at 7:31 AM 0 replies 250+ views
Original Post
Riddle
Riddle
Hello all! I have developed a GLTextureManager in the hope to make my engine API independent. The GLTextureManager inherites from TextureManager which inherites from ResourceManager. But now I have encountered a problem. I can't simply contruct the manager as I wanted: TextureManager tm = new GLTextureManager(); I must do: TextureManager tm = new GLTextureManager(); I must create some kind of GenericObjectCreater: ( I just came up with this. Not tested and no documentation. )

public static class ObjectCreator<Type>
{
    public delegate Type Creater();

    private static Creator _creator;

    public static Creator CreatorDelegate
    {
       get{ return _creator; }
       set{ _creator = value; }
    }

    public static Type Create()
    {
       return _creator();
    }
}



I would use it now like this:


Type t = GetTextureType();
TextureManager<t> tm = ObjectCreator<t>.Create();




That doesn't look so great and I don't even know if that works. Do you guys have any other Ideas? Please help me! Thank you very much. :D Riddle Here the manager class hirachy:


public abstract class ResourceManager<Type> where Type : Resource
{
}

public abstract class Resource
{
}






public abstract class TextureManager<Type> : ResourceManager<Type> where Type : Texture
{
}

public abstract class Texture : Resource
{
}






public class GLTextureManager : TextureManager<GLTexture>
{
}

public class GLTexture : Texture
{
}


PS.: I just come up witht that I could remove the gneric param. from the TextureManager and the GLTextureManager simply returns Texture objects. [Edited by - Riddle on January 24, 2005 8:15:36 AM]

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.