I have this definition of an abstract class:
public abstract class Game<T> : IGame<T> where T : IGameItem
{
public Guid Id { get; set; } = Guid.NewGuid();
protected List<T> GameItems { get; set; } = new();
public IReadOnlyList<T> Items => GameItems.AsReadOnly();
public void AddGameItem(T gameItem)
{
if(gameItem is null)
{
throw new ArgumentNullException(nameof(gameItem));
}
this.GameItems.Add(gameItem);
}
public void RemoveGameItem(T gameItem)
{
if (gameItem is null)
{
throw new ArgumentNullException(nameof(gameItem));
}
this.GameItems.Remove(gameItem);
}
}
where IGame is (IItem only contains a property Id of type Guid):
public interface IGame<T> : IItem where T : IGameItem
{
IReadOnlyList<T> Items { get; }
void AddGameItem(T gameItem);
void RemoveGameItem(T gameItem);
}
where IGameItem is inherits from IItem but it´s empty for the moment.
Then I have the definition of IWordGame which is:
public interface IWordGame : IGame<IWordGameItem>
{
*** Some properties here ***
}
And IWordGameItem inherits from IGameItem and adds some other properties.
The problem comes when I create a class that derives from Game
public class WordGame : Game<WordGameItem>, IWordGame
{
}
The class keeps complaining that I haven´t implemented the properties and methods of the IGame interface... But those methods are implemented in the Game base class... What am I missing? Do I need to restructure the arquitecture? What´s the best way to do it? If I implement the methods this is how the code goes:
IReadOnlyList<IWordGameItem> IGame<IWordGameItem>.Items => throw new NotImplementedException();
public void AddGameItem(IWordGameItem gameItem)
{
throw new NotImplementedException();
}
public void RemoveGameItem(IWordGameItem gameItem)
{
throw new NotImplementedException();
}
However I don´t want to implement the methods there but in the base class. How can I achieve that?