Solved

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

Posted on 2011-09-22
3
190 Views
Last Modified: 2012-06-21
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.
0
Comment
Question by:hpdvs2
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 8

Author Comment

by:hpdvs2
ID: 36582956
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?)
0
 
LVL 4

Accepted Solution

by:
theHollow earned 500 total points
ID: 36583311
Hello
Interfaces cannot hold code. I don't think that you have seen this anywhere :-)
So what you need to do, is what it seens that you have already done.

You have to make base class for this, instead of an interface.
 - The class itself should be marked with "abstract".
 - The method that should be overridden (QuerySet) should be marked as "abstract" as well, and hold no code
 - The method that should not be overridden (QueryTable) should not be marked with "abstract"

The abstract methods and properties will be generating a build error if not implemented when you inherit from the base class.

None of these methods needs to be marked as "static" unless you want them to be available from the class itelf without being instanced.

Hope that clearified a bit :-)
0
 
LVL 8

Author Comment

by:hpdvs2
ID: 36599746
And I'm also finding validation on this as well.  
0

Featured Post

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In order to hide the "ugly" records selectors (triangles) in the rowheaders, here are some suggestions. Microsoft doesn't have a direct method/property to do it. You can only hide the rowheader column. First solution, the easy way The first sol…
This article introduced a TextBox that supports transparent background.   Introduction TextBox is the most widely used control component in GUI design. Most GUI controls do not support transparent background and more or less do not have the…
There are cases when e.g. an IT administrator wants to have full access and view into selected mailboxes on Exchange server, directly from his own email account in Outlook or Outlook Web Access. This proves useful when for example administrator want…
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…
Suggested Courses

617 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question