472,347 Members | 2,293 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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

Declaring types in an Interface

I was surprised and somewhat disappointed by the fact that you cannot declare types in an interface. I discovered this when defining an interface that included events, where the definition of the delegates had to be placed outside the definition of the interface. To me, the delegate definition is an integral part of the interface definition. Also, I could imagine cases where one would like to define enums and structs in interfaces as well (to be used as parameter types in methods of the interface). The way it is now, these "external" definitions have to be carried along as added baggage to the interfaces, and clients have to be aware of this. They are even listed separately from the interface in the Class View tree list in Visual Studio - unless the type is given some meaningful name tag to associate it with its interface, there is no indication as to what it belongs to.

Am I missing something here, or is this a reasonable request for inclusion in a future version of the language? I would very much appreciate your comments on this.

Peter Berry
Nov 15 '05 #1
5 2761
In regards to delegates, I can say that it's a blessing that you only need
to match the signature, and not have a class implement an interface in order
to handle an event, not sure if that's what you meant, though. I don't know
what exactly your scenarios are for embedding enums in interfaces? If you
want to pass around a type with a restricted set of values, seems to me
you'd want to have it available freely detached from any interface that used
that type as a member - but that may not be your scenario. I guess I just
don't see what you 'buy' with it.

R.

--
Veuillez m'excuser, mon Français est très pauvre. Cependant, si vous voyez
mauvais C #, c'est mon défaut!
"Peter Berry" <bc******@bigpond.com> wrote in message
news:%2****************@TK2MSFTNGP11.phx.gbl...
I was surprised and somewhat disappointed by the fact that you cannot
declare types in an interface. I discovered this when defining an interface
that included events, where the definition of the delegates had to be placed
outside the definition of the interface. To me, the delegate definition is
an integral part of the interface definition. Also, I could imagine cases
where one would like to define enums and structs in interfaces as well (to
be used as parameter types in methods of the interface). The way it is now,
these "external" definitions have to be carried along as added baggage to
the interfaces, and clients have to be aware of this. They are even listed
separately from the interface in the Class View tree list in Visual Studio -
unless the type is given some meaningful name tag to associate it with its
interface, there is no indication as to what it belongs to.
Am I missing something here, or is this a reasonable request for inclusion
in a future version of the language? I would very much appreciate your
comments on this.
Peter Berry
Nov 15 '05 #2
i would really like constants to be available in the interface.

dan holmes
"Peter Berry" <bc******@bigpond.com> wrote in message news:%2****************@TK2MSFTNGP11.phx.gbl...
I was surprised and somewhat disappointed by the fact that you cannot declare types in an interface. I discovered this when defining an interface that included events, where the definition of the delegates had to be placed outside the definition of the interface. To me, the delegate definition is an integral part of the interface definition. Also, I could imagine cases where one would like to define enums and structs in interfaces as well (to be used as parameter types in methods of the interface). The way it is now, these "external" definitions have to be carried along as added baggage to the interfaces, and clients have to be aware of this. They are even listed separately from the interface in the Class View tree list in Visual Studio - unless the type is given some meaningful name tag to associate it with its interface, there is no indication as to what it belongs to.

Am I missing something here, or is this a reasonable request for inclusion in a future version of the language? I would very much appreciate your comments on this.

Peter Berry

Nov 15 '05 #3
I cannot speak for the C# designers, but my guess is that they were trying
to keep the language not unnecessarily complex.

The features you mentioned, while missed, are not indespensable. You can
achieve similar results using nested name spaces and/or abstract classes.
Like

public abstract class Foo
{
public enum Bar {...}
public const Baz = ...;

public int Method1() {...}
}

- Zhanyong Wan

Visual Studio and .NET Setup

This posting is provided "AS IS" with no warranties, and confers no rights.
Use of included samples (if any) is subject to the terms specified at
http://www.microsoft.com/info/cpyright.htm

--------------------
| From: "Dan Holmes" <dh*****@ivsi.com>
|
| i would really like constants to be available in the interface.
| dan holmes
| "Peter Berry" <bc******@bigpond.com> wrote in message
news:%2****************@TK2MSFTNGP11.phx.gbl...
| I was surprised and somewhat disappointed by the fact that you cannot
declare types in an interface. I discovered this when defining an interface
that included events, where the definition of the delegates had to be
placed outside the definition of the interface. To me, the delegate
definition is an integral part of the interface definition. Also, I could
imagine cases where one would like to define enums and structs in
interfaces as well (to be used as parameter types in methods of the
interface). The way it is now, these "external" definitions have to be
carried along as added baggage to the interfaces, and clients have to be
aware of this. They are even listed separately from the interface in the
Class View tree list in Visual Studio - unless the type is given some
meaningful name tag to associate it with its interface, there is no
indication as to what it belongs to.
| Am I missing something here, or is this a reasonable request for
inclusion in a future version of the language? I would very much appreciate
your comments on this.
| Peter Berry
|

Nov 15 '05 #4
My comment is - interface is a pain in my neck.
I cannot see any benefits of using interface.

I have to modify a system where everything is based on some kind of
interface.
I need to make a major change to one of the components. It's based on
interface and another 29 components are based on the same interface.
So either I modify that component by removing reference to the base
interface (if so, why to use interface at all) or I will have to modify
the interface and 29 components.

I will never,never use interface.

MH
Nov 15 '05 #5
Hi ,
"Marius Horak" <so*****@europe.con> wrote in message
news:uk**************@TK2MSFTNGP09.phx.gbl...
My comment is - interface is a pain in my neck.
I cannot see any benefits of using interface.
An interface is a contract, it's a corner stone of the OOP paradigm and
frankly you cannot do much in C# without using them. I could give you a
large explanation of the beneficies of them, but no today ;)
Maybe if you do a search in google for something like 'interface vs
"multiple inheritance"' you will get some links with better explanation of
the one I would possible give you.
I have to modify a system where everything is based on some kind of
interface.
You should NEVER modify an interface !!! an interface is a contract and must
be kept both by the classes that implement them as well as the interface
itself.
I need to make a major change to one of the components. It's based on
interface and another 29 components are based on the same interface.
So either I modify that component by removing reference to the base
interface (if so, why to use interface at all) or I will have to modify
the interface and 29 components.


Did you think about creating a new interface that inherit from the previous
one?
In this case you will have to modify only the component that you want, and
not the entire system.

Maybe if you create a derived class of that component that implement the new
interface you can solve your problem.
Merry X-Mas,

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation
Nov 15 '05 #6

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

Similar topics

20
by: Ole Hanson | last post by:
I am accessing my database through an interface, to allow future substitution of the physical datastore - hence I would like to declare in my...
21
by: Helge Jensen | last post by:
I've got some data that has Set structure, that is membership, insert and delete is fast (O(1), hashing). I can't find a System.Collections...
0
by: Sachin Sharma | last post by:
Hello, I am trying to write an application using some concepts of a plug-in architecture in VB.NET (learning). I have run into a problem related...
6
by: dndfan | last post by:
Hello, In the short time I have spent reading this newsgroup, I have seen this sort of declaration a few times: > int > func (string, number,...
16
by: Bob Hairgrove | last post by:
Consider the classic clone() function: class A { public: virtual ~A() {} virtual A* clone() const = 0; }; class B : public A { public:
5
by: atwomey | last post by:
When I try and place a delegate in an interface, like this : public interface ITest { double foo(); delegate void bar(); } I get an error...
2
by: Brad | last post by:
I'm using events to handle asynchronous notification upwards and interfaces across all class boundaries. I'm not sure of how to declare a delegate...
10
by: Sebastian | last post by:
Hi, I'm confronted with a problem that seems not to be solvable. In general: How can I override an interface member of my base class and call...
7
by: WTH | last post by:
I am now aware (I am primarily a C++ developer) that in C# if you reference the same interface from the same file in two different projects the...
0
better678
by: better678 | last post by:
Question: Discuss your understanding of the Java platform. Is the statement "Java is interpreted" correct? Answer: Java is an object-oriented...
0
by: Naresh1 | last post by:
What is WebLogic Admin Training? WebLogic Admin Training is a specialized program designed to equip individuals with the skills and knowledge...
0
jalbright99669
by: jalbright99669 | last post by:
Am having a bit of a time with URL Rewrite. I need to incorporate http to https redirect with a reverse proxy. I have the URL Rewrite rules made...
0
by: antdb | last post by:
Ⅰ. Advantage of AntDB: hyper-convergence + streaming processing engine In the overall architecture, a new "hyper-convergence" concept was...
2
by: Matthew3360 | last post by:
Hi, I have a python app that i want to be able to get variables from a php page on my webserver. My python app is on my computer. How would I make it...
0
by: AndyPSV | last post by:
HOW CAN I CREATE AN AI with an .executable file that would suck all files in the folder and on my computerHOW CAN I CREATE AN AI with an .executable...
0
hi
by: WisdomUfot | last post by:
It's an interesting question you've got about how Gmail hides the HTTP referrer when a link in an email is clicked. While I don't have the specific...
0
by: Matthew3360 | last post by:
Hi, I have been trying to connect to a local host using php curl. But I am finding it hard to do this. I am doing the curl get request from my web...
0
Oralloy
by: Oralloy | last post by:
Hello Folks, I am trying to hook up a CPU which I designed using SystemC to I/O pins on an FPGA. My problem (spelled failure) is with the...

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.