Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

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

Posted on 2011-09-22
3
Medium Priority
?
193 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 2000 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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

Introduction Although it is an old technology, serial ports are still being used by many hardware manufacturers. If you develop applications in C#, Microsoft .NET framework has SerialPort class to communicate with the serial ports.  I needed to…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…

704 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