I've created the following interface.
public interface IMineralService
{
Task<Mineral[]> GetMinerals(int page = 0, int size = Int32.MaxValue);
Task<Mineral> GetMineral(int id);
}
Its implementation is as follows.
public class MineralService : IMineralService
{
public async Task<Mineral[]> GetMinerals(int page = 0, int size = Int32.MaxValue)
{
Mineral[] data = await Task.FromResult(Minerals);
return data.Skip(page * size).Take(size).ToArray();
}
public async Task<Mineral> GetMineral(int id)
{
Mineral[] data = await GetMinerals();
return data.SingleOrDefault(a => a.Id == id);
}
}
I don't understand what's the purpose or implication of declaring the default values for the parameters both in the constructor and in the implementation. Skipping the default values doesn't collide with implementing the interface as such, so the following would work. Id est - there's no imposition of the set defaults from the interface onto the implementation.
public interface IMineralService
{
Task<Mineral[]> GetMinerals(int page = 0, int size = Int32.MaxValue);
}
public class MineralService : IMineralService
{
public async Task<Mineral[]> GetMinerals(int page, int size) { ... }
}
It also works with the defaults only being declared in the implementation.
public interface IMineralService
{
Task<Mineral[]> GetMinerals(int page, int size);
}
public class MineralService : IMineralService
{
public async Task<Mineral[]> GetMinerals(int page = 0, int size = Int32.MaxValue)
}
However, in order to make the second method work with await GetMinerals(), the defaults must be set in the implementation. So what's the point of ever setting the default in the constructor if it must be re-stated in the implementation (if it's used by another call) or isn't needed at all (if there's no other call utilizing the defaults)?