473,796 Members | 2,559 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 2828
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******@bigpo nd.com> wrote in message
news:%2******** ********@TK2MSF TNGP11.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******@bigpo nd.com> wrote in message news:%2******** ********@TK2MSF TNGP11.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.c om>
|
| i would really like constants to be available in the interface.
| dan holmes
| "Peter Berry" <bc******@bigpo nd.com> wrote in message
news:%2******** ********@TK2MSF TNGP11.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******** ******@TK2MSFTN GP09.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
4263
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 Interface that my DAL-objects implementing the interface and accessing the datastore MUST pass in a UserToken in the constructor of the object. Is this not possible? Am I forced to add the UserToken as a property on the object instead? /Ole
21
13850
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 interface that matches the operations naturally offered by Sets. - ICollection cannot decide containment - IList promises indexability by the natural numbers, which is not achievable (since i hash elements, not sort them). - IDictionary is definatly not setlike. Although I can, of course, define...
0
907
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 to exceptions that I want to throw from the plug-ins. As advised, I wrote a class library with an interface IBase. Then I wrote two more class libraries with classes that inherit from IBase, say Derived1 and Derived2. In the application, I then added references to IBase, Derived1 and...
6
2100
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, structure) > char* string > int number > struct some_struct structure
16
3205
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
29802
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 "delegates cannot declare types". What is it about a delegate that makes it incompatible in an interface. I know that an interface cannot have any implementation - is there some implementation
2
4061
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 and its associated event through the interface. I need to be able to declare this information in the interface so that the caller can register for the event. Am I missing something simple? TIA Brad
10
6955
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 the overridden method from my derived class? This is my class: class RemoteXmlDataSource : System.Web.UI.WebControls.XmlDataSource And I want to override
7
10600
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 types are actually incompatible. I found this out because I have written a generic plugin system for my current and future C# needs. I defined a base plugin system interface named IPlugin (original, I know...) which contains some basic plugin infomration all plugins of this system must expose...
0
9525
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
10221
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10169
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10003
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
9050
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...
0
5569
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4115
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3730
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2924
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.