By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,534 Members | 943 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,534 IT Pros & Developers. It's quick & easy.

Defining constructors in an interface

P: n/a
SA
Hi all,

How could I go about defining ctors in an interface. (not to instantiate the
interface, of course, but to force the implementing class to provide a
specific ctor).

Sub New(ByVal x as MyType) doesn't work.

May be it's not possible, in which case it should be on the to-do list for
future versions...

--

Sven

Nov 20 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
Bob
It's not possible and by some people's thinking (sorry, the thread is not on
the news server any more) it's "the exception that proves the rule" because
you can't instantiate an interface.

I think that's crap, because the compiler already throws an exception when
you try to instantiate a bare interface; allowing constructors in interface
definitions would cause no harm, and fill a gaping hole in the few (i.e.
serialization) that actually require certain constructor signatures to work.

Unfortunately I don't think it's on the list of 2005 enhancements.

Bob

"SA" <in*********@freemail.nl> wrote in message
news:ec**************@tk2msftngp13.phx.gbl...
Hi all,

How could I go about defining ctors in an interface. (not to instantiate the interface, of course, but to force the implementing class to provide a
specific ctor).

Sub New(ByVal x as MyType) doesn't work.

May be it's not possible, in which case it should be on the to-do list for
future versions...

--

Sven


Nov 20 '05 #2

P: n/a
SA
Bob:

Thanks for the answer, even though it isn't what I expected... :o)

--

Sven
"Bob" <no****@nowhere.com> wrote in message
news:eb**************@TK2MSFTNGP11.phx.gbl...
It's not possible and by some people's thinking (sorry, the thread is not on the news server any more) it's "the exception that proves the rule" because you can't instantiate an interface.

I think that's crap, because the compiler already throws an exception when
you try to instantiate a bare interface; allowing constructors in interface definitions would cause no harm, and fill a gaping hole in the few (i.e.
serialization) that actually require certain constructor signatures to work.
Unfortunately I don't think it's on the list of 2005 enhancements.

Bob

"SA" <in*********@freemail.nl> wrote in message
news:ec**************@tk2msftngp13.phx.gbl...
Hi all,

How could I go about defining ctors in an interface. (not to instantiate

the
interface, of course, but to force the implementing class to provide a
specific ctor).

Sub New(ByVal x as MyType) doesn't work.

May be it's not possible, in which case it should be on the to-do list for future versions...

--

Sven

Nov 20 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.