473,662 Members | 2,752 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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(stri ng productCode)

The OrderDetail table should be:

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

interface IDataEditable
{
void LoadRecord();
void SaveRecord();
}
Aug 23 '06 #1
2 1714
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(obje ct[] 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(stri ng productCode);
LoadRecord(stri ng orderNumber, string productCode);

// Impl 1
LoadRecord(stri ng productCode)
{
// do stuff
}

LoadRecord(stri ng productCode, string orderNumber)
{
LoadRecord(prod uctCode); // ignore order number
}

Impl 2

// Impl 1
LoadRecord(stri ng productCode)
{
throw new NotSupportedExc eption();
}

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

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

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

LoadRecord(ILoa dRecordInfo 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(stri ng productCode)

The OrderDetail table should be:

LoadRecord(stri ng 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.comwro te:
>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(str ing productCode)

The OrderDetail table should be:

LoadRecord(str ing 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(para ms string[] values);
void SaveRecord(para ms 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
8850
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 want my users to be able to select a report, click on a command button on a form, which will then automatically create the report as a pdf file and save it to the user's machine. I am using Adobe Acrobat (5.0 I think) and have Adobe Distiller as a
1
2836
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 directly, I'm having tons of trouble. (lots of research, lots of newsgroups, but no success! I have an existing COM+ object "Company.Person" which has several interfaces. To load my object, I have to invoke a method that is "Imported" to "Person", the...
4
1181
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 class of the data stored in the file. what i would like to know is: is there a way to make the function take a generic class without having to create a ton of overloaded versions of the method or using a switch statement and replicating the code?...
5
10365
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
5809
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 would like to support. During the code generation phase, I add an "Implements Ixxx" for each interface they select, but I've not yet figured out how to add the skeleton implementation for those interfaces. Once the user opens the class in the VS...
6
1591
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 Iball interface. ... I read its a method without an implemetnation.. like an abstract I think.. so how does it serve this project?
13
2418
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 single Object by itself, I'd like to assign a reference to the class type and call it later without knowing the derived type. Example:
9
3448
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
8435
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8345
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8857
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8633
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7368
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6186
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5655
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4181
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
2
1754
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.