Link to home
Start Free TrialLog in
Avatar of Dan Violet Sagmiller (He/Him)
Dan Violet Sagmiller (He/Him)Flag for United States of America

asked on

Interface Method 1 to keep and 1 to override...

Hello, I have a data connection wrapper I'm building to allow programs to act as the data source for another.

Here is the issue.  I have an interface, "IDataEngine", and in it, it has 2 methods.  (more, but it only needs 2 for this example of it)  
The Methods are,

public DataSet QuerySet(string sql); // inheriting classes should need to override this;

public DataTable QueryTable(string sql) // inheriting classes should not need to override this.
{
  // does error checking but is essentially,
  return QuerySet(sql).Tables[0];
}

Clearly, I do not need EVERY inheriting app to rewrite the same code for QueryTable, since it will be the same EVERY time.  

But so far, every time I tell a class to implement the IDataEngine interface, it overrides the methods that have code as well as the ones without.

How do I change this, so overriding classes do not need to rewrite methods that are already functional on an interface?  Thanks.
Avatar of Dan Violet Sagmiller (He/Him)
Dan Violet Sagmiller (He/Him)
Flag of United States of America image

ASKER

I just resolved it one way, but using an abstract class, and marking only the few methods, like QuerySet to abstract as well.

Despite that, I'm sure I've seen this done with an interface, but its dificult finding this kind of information by searching.

Anyone know if this can be done with an interface?  (without producing static methods that the overiding methods can call?)
ASKER CERTIFIED SOLUTION
Avatar of theHollow
theHollow
Flag of Norway image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
And I'm also finding validation on this as well.