I'm preparing in Monogame a little game engine, where I would want to have something like gameObject composed from DrawableObject And ClickHandler(i.e:
public class GameObject : DrawableObject, ClickHandler
Problem is - C# doesn't support multiple inheritance, I would need to use interface. I've made DrawableObject and ClickHandler abstract classes, so they can have some functionality already implemented.
public abstract class ClickHandler
{
public class NullClick : ClickHandler
{
public override void Click(Point mousePos)
{
Debug.Print("Clicked on: " + mousePos + ". NullClickHandler assigned");
}
}
private readonly byte _handlerId;
public static readonly NullClick NullClickHandler = new NullClick();
private ClickHandler() {}
public ClickHandler(ref ClickMap clickMap)
{
_handlerId = clickMap.registerNewClickHandler(this);
}
public abstract void Click(Point mousePos);
void unregisterHandler(ref ClickMap clickMap)
{
clickMap.releaseHandler(_handlerId);
}
}
class DrawableObject
{
Texture2D texture;
public Rectangle position;
public DrawableObject()
{
position = Rectangle.Empty;
}
void Load(ref GraphicsDevice graphics)
{
using (var stream = TitleContainer.OpenStream("Content/placeholder.jpg"))
{
texture = Texture2D.FromStream(graphics, stream);
position.Width = texture.Width;
position.Height = texture.Height;
}
}
void Draw(){} //here is going to be some default implementation
}
Any tips how I could redesign this to be able to implement it? I would like to not have to move whole implementation to every class in which i derive this as interface.