I'm trying to understand some interface implementation specifics and need some basic help. Given the next code:
public interface IGameObject
{
Vector3 GetSomePosition();
}
public interface IPlayer : IGameObject
{
void Die();
}
public class Player : GameObject, IPlayer
{
void Die() { }
}
Can I implement the IGameObject interface in some other class instead of Player class and use the implementation of that other class? For example some special class called "GameObjectImplementation", that implements the IGameObject interface. Since I can't inherit from two classes, how do I go about this?
-----------------------------EDIT---------------------------
Best solution I found for now was to make a base class.
public abstract class PlayerBase : GameObject, IGameObject
{
public Vector3 GetSomePosition()
{
return this.transform.Position;
}
}
public class Player : PlayerBase, IPlayer
{
void Die() { }
}
Any other suggestions? Like injection or some way of explicit implementations? Or is this the best way to do it already?