As a novice to OOP, I am trying to implement an interface method with a base parameter by passing a (needed) subclass parameter. I have:
public interface IArticleDataAccess { int SaveArticle(NewsArticle thisArticle); }
public AnalysisDataAccess : IArticleDataAccess {
public int SaveArticle(AnalysisArticle thisArticle) {
// Specific save code that needs properties of AnalysisArticle not found in NewsArticle.
}
public class AnalysisArticle : NewsArticle {
IArticleDataAccess dataAccess = new ArchivedArticleDataAccess();
int Save() {
return dataAccess.SaveArticle(this);
}
}
The error is "ArchivedArticleDataAccess' does not implement interface member 'IArticleDataAccess.SaveArticle(NewsArticle)'" as the parameter types are not the same.
Am I making a small mistake or missing a fundemental OOP concept? Is there a pattern I can use to do this? Casting or Generics? Or is this a limitation of C# (no contravariant parameter support)?