I have the following code sections and I am trying to implement a method that returns a list. My structure is as follows : abstract class "Coordinates" -> public class "YCoordinate" with my interface pointing to "YCoordinate". I don't want my interface directly chatting to my abstract class as I feel the implementations of my abstract class is responsible for work.
Interface :
interface IYCoordinate
{
System.Collections.Generic.List<Coordinates> GetYCoordinateList();
}
Abstract class :
public abstract class Coordinates
{
private int coordinatePriority;
private int coordinate;
public Coordinates(int CoordinatePriority, int Coordinate)
{
this.CoordinatePriority = CoordinatePriority;
this.Coordinate = Coordinate;
}
public Coordinates() { }
public int CoordinatePriority { get { return coordinatePriority; } set { coordinatePriority = value; } }
public int Coordinate { get { return coordinate; } set { coordinate = value; } }
public virtual List<Coordinates> GetYCoordinateList()
{
throw new System.NotImplementedException();
}
}
Implementation of Interface and abstract class (this is the part that breaks):
public class YCoordinate : Coordinates, IYCoordinate
{
public override List<Coordinates> GetYCoordinateList()
{
List<Coordinates> _list = new List<Coordinates>();
_list.Add(new IYCoordinate(1, 5000));
_list.Add(new IYCoordinate(2, 100000));
return _list;
}
}
However, I am trying to return a list of Coordinates and getting stuck on the public override function in the "YCoordinate" class as I cannot instantiate the Coordinates class directly (because its abstract). How can I return a list of Coordinates? The same error happens if I put in IYCoordinate as shown above.
Maybe my implementation is completely wrong? Any recommendation for doing it better would be welcome.
Later on there will be XCoordinate class and so on. If this approach seems like a bit much its because I am trying to get the hang of the theory behind this.