473,395 Members | 2,713 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,395 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 2810
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 Interface that my DAL-objects implementing the...
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 interface that matches the operations naturally offered...
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 to exceptions that I want to throw from the...
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, structure) > char* string > int 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 "delegates cannot declare types". What is it about a...
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 and its associated event through the interface. I...
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 the overridden method from my derived class? This...
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 types are actually incompatible. I found this out...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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
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...
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
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,...
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
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...
0
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...
0
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...

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.