473,387 Members | 1,529 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Can I create an Interface which have a method have variate type parameters?

ABC
Can I create an Interface which have a method have variate type parameters?

I want create an Interface named IDataEditable which have two methods:
LoadRecord and SaveRecord.

As the LoadRecord have variate type parameters based on the record primary
key definition such as:

The product table should be:

LoadRecord(string productCode)

The OrderDetail table should be:

LoadRecord(string OrderNo, string ProductCode)
Should I write the code as follow?

interface IDataEditable
{
void LoadRecord();
void SaveRecord();
}
Aug 23 '06 #1
2 1683
I think you should rethink this structure.
The concept of an interface is that it enables 1 or many objects to be
treated in exactly the same way, however, the requirement of different
parameters means that it cannot treat these method calls in the same way, so
combining these method calls in an interface is pointless.

You could implement:

LoadRecord(object[] args);

Although I wouldn't recommend such a lack of type-safe arguments as a
consumer could pass 1 argument instead of two causing an IndexOutOfRange
exception.

You could implement

LoadRecord(string productCode);
LoadRecord(string orderNumber, string productCode);

// Impl 1
LoadRecord(string productCode)
{
// do stuff
}

LoadRecord(string productCode, string orderNumber)
{
LoadRecord(productCode); // ignore order number
}

Impl 2

// Impl 1
LoadRecord(string productCode)
{
throw new NotSupportedException();
}

LoadRecord(string productCode, string orderNumber)
{
// do stuff
}

But sooner or later Impl2 will be called with only 1 string firing the
NotSupportedException.

I'd recommend you modify this idea to some else, maybe:

LoadRecord(ILoadRecordInfo info)

Creating a new object that provides information about a request for loading
information, this can have an order number and product number etc.

HTH

"ABC" wrote:
Can I create an Interface which have a method have variate type parameters?

I want create an Interface named IDataEditable which have two methods:
LoadRecord and SaveRecord.

As the LoadRecord have variate type parameters based on the record primary
key definition such as:

The product table should be:

LoadRecord(string productCode)

The OrderDetail table should be:

LoadRecord(string OrderNo, string ProductCode)
Should I write the code as follow?

interface IDataEditable
{
void LoadRecord();
void SaveRecord();
}
Aug 23 '06 #2
On Wed, 23 Aug 2006 14:39:03 +0800, "ABC" <ab*@abc.comwrote:
>Can I create an Interface which have a method have variate type parameters?

I want create an Interface named IDataEditable which have two methods:
LoadRecord and SaveRecord.

As the LoadRecord have variate type parameters based on the record primary
key definition such as:

The product table should be:

LoadRecord(string productCode)

The OrderDetail table should be:

LoadRecord(string OrderNo, string ProductCode)
Should I write the code as follow?

interface IDataEditable
{
void LoadRecord();
void SaveRecord();
}
No, this will not allow any parameters to be passed to your methods.
Use the "params" keyword instead:

interface IDataEditable
{
void LoadRecord(params string[] values);
void SaveRecord(params string[] values);
}

This will allow you to pass any number of string parameters to your
Interface methods. Each method will need to count the number of its
parameters to determine what action to take.

rossum

Aug 23 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: dog | last post by:
I've seen plenty of articles on this topic but none of them have been able to solve my problem. I am working with an Access 97 database on an NT4.0 machine, which has many Access reports. I...
1
by: Jim | last post by:
Hey all I'm trying to late bind a VB6 object in Component Services using c#. I've been able to do tons of late binding, but now that I have a com+ object that doesn't have a method exposed...
4
by: Shawn | last post by:
Hi All; i have created a class that handles file input and output. one of the methods loads data from a file then returns a hashtable filled with data class. it takes in the file name and the...
5
by: LS | last post by:
Can a WebMethod return an Interface type? Can we pass an interface parameter ? Example : public interface IEntity { long Id { get; set; } string Name { get; set; } }
8
by: Bill Rust | last post by:
I've created an "Add Item" wizard for VB.NET 2003 that allows a user to add a specialized class that works with my application framework. In the wizard, the user can select the interfaces they...
6
by: jason | last post by:
I found the below example online, while trying to under Interfaces. In layman's terms, can somebody explain what the purpose of this line is: void SportCharacteristics(); //LOCATED IN THE...
13
by: docschnipp | last post by:
Hi, I have a bunch of object derived from the same base class. They all share the same constructor with some parameters. Now, instead of using a large switch() statement where I call every...
9
by: Grant Schenck | last post by:
Hello, I have a base class with several derived classes: ScriptBase + ScriptCallInbound + ScriptCallOutbound I then have another class: Line
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.