473,320 Members | 1,858 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,320 software developers and data experts.

C# Feature Request (Interface Extensions)

A feature that I find signficantly missing in C# is the ability to write
functions in interfaces that can call other functions of the interface.
Given an interface ISomeInteface the only way we can write a general purpose
function to operate on all objects which implement that interface is through
the following style of declaration (in the following code snippets i is an
interface variable of type ISomeInterface) :

SomeStaticClass {
FuBar(ISomeInterface i) { ... }
}

Which when invoked requires the following syntax :

SomeStaticClass.FuBar(i);
What would be more appropriate would be to be able to define interface
functions which allow the more straightforward object-like syntax of :

i.FuBar()

For lack of a better term I refer to these kinds of functions as interface
extensions, in order to distinguish them from interface contract (the set of
functions to be implemented, by an implementor of the interface). One
possible approach for adding this feature is to prefix extension functions
with a keyword modifier, such as in the following notation :

SomeInterface {
extension FuBar() { ... }
}

Another possibility, and my preferred option, is to divide the interface
into two sections :

SomeInterface {
contract
...
extension
FuBar();
}

For more information on extensions as implemented by Heron, there is a first
draft of a paper at : http://www.heron-language.com/extensions.html . I
would like to know what others think of this proposal (both the feature and
the presentation of the feature) and what the proper channels are for
feature proposal to C#. Thanks in advance for your feedback.

--
Christopher Diggins
yet another language designer
http://www.heron-language.com
Nov 15 '05 #1
4 2075
Why don't you just use abstract classes?

Nicolas di Tada
Manas - Technology Solutions
http://www.manas.com.ar

On Wed, 4 Feb 2004 13:25:49 -0500, "christopher diggins"
<cd******@users.sourceforge.net> wrote:
A feature that I find signficantly missing in C# is the ability to write
functions in interfaces that can call other functions of the interface.
Given an interface ISomeInteface the only way we can write a general purpose
function to operate on all objects which implement that interface is through
the following style of declaration (in the following code snippets i is an
interface variable of type ISomeInterface) :

SomeStaticClass {
FuBar(ISomeInterface i) { ... }
}

Which when invoked requires the following syntax :

SomeStaticClass.FuBar(i);
What would be more appropriate would be to be able to define interface
functions which allow the more straightforward object-like syntax of :

i.FuBar()

For lack of a better term I refer to these kinds of functions as interface
extensions, in order to distinguish them from interface contract (the set of
functions to be implemented, by an implementor of the interface). One
possible approach for adding this feature is to prefix extension functions
with a keyword modifier, such as in the following notation :

SomeInterface {
extension FuBar() { ... }
}

Another possibility, and my preferred option, is to divide the interface
into two sections :

SomeInterface {
contract
...
extension
FuBar();
}

For more information on extensions as implemented by Heron, there is a first
draft of a paper at : http://www.heron-language.com/extensions.html . I
would like to know what others think of this proposal (both the feature and
the presentation of the feature) and what the proper channels are for
feature proposal to C#. Thanks in advance for your feedback.


Nov 15 '05 #2
Once you add functionality to an interface, it is no longer an interface -
it's a class.

And you don't end up as a static class like the code you posted, you end up
with
public abstract class SomeAbstractBase{
public void SomeContractFunction();
public void FuBar(){
SomeContractFunction();
}
}
unless what you REALLY want is multiple inheritance, which c# does *not*
have.

While I think there are a lot of good arguments about multiple inheritance
both ways, I can easily count on one hand the number of times not having it
has caused me a problem. Many people consider missing MI to be a huge lack.
Others think its a boon.

However, making interfaces into abstract classes but still calling them
interfaces isn't going to resolve the issue -- it's just renaming it.
Renaming it in a confusing way, at that.

"christopher diggins" <cd******@users.sourceforge.net> wrote in message
news:0N*********************@weber.videotron.net.. .
A feature that I find signficantly missing in C# is the ability to write
functions in interfaces that can call other functions of the interface.
Given an interface ISomeInteface the only way we can write a general purpose function to operate on all objects which implement that interface is through the following style of declaration (in the following code snippets i is an
interface variable of type ISomeInterface) :

SomeStaticClass {
FuBar(ISomeInterface i) { ... }
}

Which when invoked requires the following syntax :

SomeStaticClass.FuBar(i);
What would be more appropriate would be to be able to define interface
functions which allow the more straightforward object-like syntax of :

i.FuBar()

For lack of a better term I refer to these kinds of functions as interface
extensions, in order to distinguish them from interface contract (the set of functions to be implemented, by an implementor of the interface). One
possible approach for adding this feature is to prefix extension functions
with a keyword modifier, such as in the following notation :

SomeInterface {
extension FuBar() { ... }
}

Another possibility, and my preferred option, is to divide the interface
into two sections :

SomeInterface {
contract
...
extension
FuBar();
}

For more information on extensions as implemented by Heron, there is a first draft of a paper at : http://www.heron-language.com/extensions.html . I
would like to know what others think of this proposal (both the feature and the presentation of the feature) and what the proper channels are for
feature proposal to C#. Thanks in advance for your feedback.

--
Christopher Diggins
yet another language designer
http://www.heron-language.com

Nov 15 '05 #3
<Nicolas di Tada> wrote in message
news:1h********************************@4ax.com...
Why don't you just use abstract classes?

Nicolas di Tada
Manas - Technology Solutions
http://www.manas.com.ar


Because you can not have multiple inheritance of base classes.

Conceptually an extension is a top-down approach rather than a bottom up
approach. Using an abstract class to express a contract as in an interface
is not clear design concept, if it were then there would be no need to
explicitly have interfaces in the first place.

--
Christopher Diggins
yet another language designer
http://www.heron-language.com
Nov 15 '05 #4

"Philip Rieck" <st***@mckraken.com> wrote in message
news:u5**************@tk2msftngp13.phx.gbl...
Once you add functionality to an interface, it is no longer an interface -
it's a class.
By some defintions, but we shouldn't allow ourselves to be boxed in by
definitions.
And you don't end up as a static class like the code you posted, you end up with
public abstract class SomeAbstractBase{
public void SomeContractFunction();
public void FuBar(){
SomeContractFunction();
}
}
This is a work-around but not functionally equivalent to what I posted.

unless what you REALLY want is multiple inheritance, which c# does *not*
have.
That is not what I really want. I am aware C# does not have multiple
inheritance of classes.
While I think there are a lot of good arguments about multiple inheritance
both ways, I can easily count on one hand the number of times not having it has caused me a problem. Many people consider missing MI to be a huge lack. Others think its a boon.
Unless what I really want are interface with extensions. Interfaces with
extensions do not introduce all of the properties of multiple inheritance.
For instance you do not have multiple inheritance of data, nor do you have
multiple inheritance of contract implementation. Comparing it with multiple
inheritance of classes is just not correct.
However, making interfaces into abstract classes but still calling them
interfaces isn't going to resolve the issue -- it's just renaming it.
Renaming it in a confusing way, at that.


You are oversimplifying what I proposed. An abstract base class is not
equivalent to an interface with extensions. Some of the differences are :
1) interface with extensions can not contain data
2) the implementation of an interface with extension can not also be an
interface with extensions
3) you can not partially implement the contract of an interface with
extensions
4) you can not have virtual yet non-abstract functions in an interface with
extensions
5) you can inherit multiple interfaces (as you pointed out),

Overall the problems with ABC's is that they blur the distinction between
divisions of interface and implementation.

Best regards,

Christopher Diggins
yet another language designer
http://www.heron-language.com
Nov 15 '05 #5

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

Similar topics

21
by: Michele Simionato | last post by:
I often feel the need to extend the string method ".endswith" to tuple arguments, in such a way to automatically check for multiple endings. For instance, here is a typical use case: if...
30
by: Raymond Hettinger | last post by:
Proposal -------- I am gathering data to evaluate a request for an alternate version of itertools.izip() with a None fill-in feature like that for the built-in map() function: >>> map(None,...
32
by: toolmaster | last post by:
Since many of the modern computer languages have built-in namespace features, I can't understand why not add this feature into standard C. I've heard many people complain of the lacking of...
1
by: Plamen | last post by:
Hi , I need to change the ToolTip in Windows explorer that is shown when the cursor is over a file. Here is how it should work: you create a class that imports IPersistFile and IQueryInfo. After...
3
by: Jacob | last post by:
Hi All, Is there a way to get the contents of a web service request? Preferably including the HTTP headers too. I tried saving Context.Request.InputStream to a stream, but it always appears...
19
by: George Sakkis | last post by:
It would be useful if list.sort() accepted two more optional parameters, start and stop, so that you can sort a slice in place. In other words, x = range(1000000) x.sort(start=3, stop=-1) ...
11
by: subramanian | last post by:
Suppose int size = INT_MAX / 8; char a; are declared to use the feature of variable lenght array(VLA) in C99. With appropriate #includes, when this code is run, segmentation fault occurs in Red...
7
by: Ido Samuelson | last post by:
Hello, What do you think about the following features: public class GenericDecorator<T: T { } can leverage to a few things:
10
by: Conrad Lender | last post by:
In a recent thread in this group, I said that in some cases object detection and feature tests weren't sufficient in the development of cross-browser applications, and that there were situations...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.