473,403 Members | 2,366 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,403 software developers and data experts.

About Interface

Hello!

The keword abstract and sealed are not allowed in interfaces.
I can understand that abstract is not allowed because an interface is
completely abstract
and contains no implementation.

As mentioned before sealed is not allowed in an interface because it makes
not sense is the reason that is mentioned but if we have
this construction it would make sense. Here we are not allowed to inherit
the interface IMyBaseInterface

public sealed interface IMyInterface : IMyBaseInterface
{
....
}

//Tony
Jun 27 '08 #1
9 1687
On Wed, 04 Jun 2008 23:45:20 -0700, Tony <jo*****************@telia.com>
wrote:
The keword abstract and sealed are not allowed in interfaces.
I can understand that abstract is not allowed because an interface is
completely abstract
and contains no implementation.
Right..."abstract" would be redundant. :)
As mentioned before sealed is not allowed in an interface because it
makes
not sense is the reason that is mentioned but if we have
this construction it would make sense. Here we are not allowed to inherit
the interface IMyBaseInterface

public sealed interface IMyInterface : IMyBaseInterface
{
...
}
You could also have sealed an interface that doesn't inherit any other
interface.

But why would you do that?

Interfaces can inherit other interfaces. But they never inherit any
implementation. The reason for sealing a class is to ensure that the
sealed class is guaranteed to be the final word with respect to the
implementation. Imagine, for example, if String wasn't sealed and you
could override its ToString() method. The havok one could wreak with that
sort of thing!

But you can't override anything in an interface. You can only add new
members to the base interface. Since there's no real way to screw up a
base interface through inheritance, there's no need to allow the author of
an interface to prevent any other interface from inheriting it.

Pete
Jun 27 '08 #2
Hi Tony,

Why shouldn't you be able to inherit from an interface. You can't change
the original implementation. Consider the example

interface Unherited
{
string Text { get;}
}

interface Inherited : Unherited
{
new string Text { set;}
}

class MyClass : Inherited
{
#region Inherited Members

public string Text
{
set { }
}

#endregion

#region Unherited Members

string Unherited.Text
{
get { return "Hello"; }
}

#endregion
}

You still need to implement a getter property so

string s = ((Unherited)MyClass).Text;

is still valid.

--
Happy Coding!
Morten Wennevik [C# MVP]
"Tony" wrote:
Hello!

The keword abstract and sealed are not allowed in interfaces.
I can understand that abstract is not allowed because an interface is
completely abstract
and contains no implementation.

As mentioned before sealed is not allowed in an interface because it makes
not sense is the reason that is mentioned but if we have
this construction it would make sense. Here we are not allowed to inherit
the interface IMyBaseInterface

public sealed interface IMyInterface : IMyBaseInterface
{
....
}

//Tony
Jun 27 '08 #3
Tony wrote:
Hello!

The keword abstract and sealed are not allowed in interfaces.
I can understand that abstract is not allowed because an interface is
completely abstract
and contains no implementation.

As mentioned before sealed is not allowed in an interface because it makes
not sense is the reason that is mentioned but if we have
this construction it would make sense. Here we are not allowed to inherit
the interface IMyBaseInterface

public sealed interface IMyInterface : IMyBaseInterface
{
...
}

//Tony
If you could make an interface sealed then it would be totally useless,
as you can neither inherit it nor implement it.

--
Göran Andersson
_____
http://www.guffa.com
Jun 27 '08 #4
On Thu, 05 Jun 2008 00:40:40 -0700, Göran Andersson <gu***@guffa.com>
wrote:
If you could make an interface sealed then it would be totally useless,
as you can neither inherit it nor implement it.
To be fair to Tony, that all depends on the definition of "sealed".
There's no reason that the "sealed" keyword _must_ mean that an interface
can't be implemented. The language _could_ treat interface inheritance
differently from interface implementation for the purpose of an interface
being "sealed".

It still wouldn't make sense to allow interfaces to be sealed, but for
somewhat subtler reasons than if one makes a broader assumption about that
"sealed" might mean.

Pete
Jun 27 '08 #5
So let's just say for now that you could seal the interface, what would be
the difference between:

----------------------------
// The way thing work now:

interface IA
{
void WhateverOnA();
}

interface IB : IA
{
void WhateverOnB();
}

class SomeClass : IB
{
public void WhateverOnA()
{
throw new NotImplementedException();
}

public void WhateverOnB()
{
throw new NotImplementedException();
}
}

------------ And --------------
// Allowing interfaces to be sealed:

sealed interface IA // Sealed
{
void WhateverOnA();
}

interface IB // Cant inherit from IA
{
void WhateverOnB();
}

class SomeClass : IA, IB
{
public void WhateverOnA()
{
throw new NotImplementedException();
}

public void WhateverOnB()
{
throw new NotImplementedException();
}
}

----------------------------

What exactly was accomplished here? What was prevented from happening?

The first example show interfaces being inherited the way they work now, the
second example shows interface "IA" sealed so there was no way to inherit
form it but never the less, at the end, I was able to accomplish the exact
same thing as on the first example.

Cheers.

"Tony" <jo*****************@telia.comwrote in message
news:%2***************@TK2MSFTNGP02.phx.gbl...
Hello!

The keword abstract and sealed are not allowed in interfaces.
I can understand that abstract is not allowed because an interface is
completely abstract
and contains no implementation.

As mentioned before sealed is not allowed in an interface because it makes
not sense is the reason that is mentioned but if we have
this construction it would make sense. Here we are not allowed to inherit
the interface IMyBaseInterface

public sealed interface IMyInterface : IMyBaseInterface
{
...
}

//Tony

Jun 27 '08 #6
Peter Duniho wrote:
On Thu, 05 Jun 2008 00:40:40 -0700, Göran Andersson <gu***@guffa.com>
wrote:
>If you could make an interface sealed then it would be totally
useless, as you can neither inherit it nor implement it.

To be fair to Tony, that all depends on the definition of "sealed".
There's no reason that the "sealed" keyword _must_ mean that an
interface can't be implemented. The language _could_ treat interface
inheritance differently from interface implementation for the purpose of
an interface being "sealed".
It could, but that wouldn't really make sense. To be reasonably
consistent, a sealed interface would only be allowed to be implemented
by a sealed class, otherwise implementing the interface would
effectively un-seal it.

--
Göran Andersson
_____
http://www.guffa.com
Jun 27 '08 #7
On Fri, 06 Jun 2008 07:05:57 -0700, Göran Andersson <gu***@guffa.com>
wrote:
>There's no reason that the "sealed" keyword _must_ mean that an
interface can't be implemented. The language _could_ treat interface
inheritance differently from interface implementation for the purpose
of an interface being "sealed".

It could, but that wouldn't really make sense.
????

The whole point of this thread is that "sealed" doesn't make sense
regardless. The phrase "wouldn't really make sense" is useless for
distinguishing between two different interpretations, neither of which
make sense.

My point is that your intepretation isn't the only one, and it
prejudicially makes even less sense than a more operational interpretation
would.
To be reasonably consistent, a sealed interface would only be allowed to
be implemented by a sealed class, otherwise implementing the interface
would effectively un-seal it.
Again, this depends entirely on one's definition of "sealed interface" and
what the intent behind that attribute would be. I agree that's one
possible interpretation, but it's not the only one, and even if it were,
it's not the explanation for why using "sealed" on interfaces doesn't make
sense.

Pete
Jun 27 '08 #8
Peter Duniho wrote:
The whole point of this thread is that "sealed" doesn't make sense
regardless. The phrase "wouldn't really make sense" is useless for
distinguishing between two different interpretations, neither of which
make sense.
So what are you arguing about, then? Do you want it to not make sense?
You are not making very much sense...
My point is that your intepretation isn't the only one
I never said that it was. Stop putting words in my mouth. It's very
annoying when you do that.
I agree that's one
possible interpretation, but it's not the only one, and even if it were,
it's not the explanation for why using "sealed" on interfaces doesn't
make sense.
So you are the one that is deciding that? Noone else has the right to
have an opinion?

--
Göran Andersson
_____
http://www.guffa.com
Jun 27 '08 #9
On Sat, 07 Jun 2008 02:03:27 -0700, Göran Andersson <gu***@guffa.com>
wrote:
Peter Duniho wrote:
>The whole point of this thread is that "sealed" doesn't make sense
regardless. The phrase "wouldn't really make sense" is useless for
distinguishing between two different interpretations, neither of which
make sense.

So what are you arguing about, then?
I'm not arguing about anything. I'm making a factual observation about
your original, incorrect assumption.
Do you want it to not make sense? You are not making very much sense...
I can readily believe that I'm not making much sense _to you_. That's not
the same as me not making sense though. All it really means is that you
have a chip on your shoulder and are willing to make broad generalizations
about what I am or am not doing.
>My point is that your intepretation isn't the only one

I never said that it was. Stop putting words in my mouth. It's very
annoying when you do that.
You wrote:

"If you could make an interface sealed then it would be totally useless,
as you can neither inherit it nor implement it".

I'm not putting words in your mouth. Your statement purports to explain
why a sealed interface would be useless, but it makes an assumption that
isn't a given. It's simply not true that a sealed interface would de
facto not be able to be implemented. Given that the assumption is false,
it's not useful in explaining why a sealed interface would be useless.

I haven't written anything that claims you said something you didn't. If
you are annoyed, it's because you have falsely inferred some behavior
that's not actually happening.
>I agree that's one possible interpretation, but it's not the only one,
and even if it were, it's not the explanation for why using "sealed" on
interfaces doesn't make sense.

So you are the one that is deciding that? Noone else has the right to
have an opinion?
You are welcome to your opinion, and that's true even when it's wrong.
But you can't expect to make factual assumptions that have
counter-examples proving the assumption to be false without having those
counter-examples pointed out.

Pete
Jun 27 '08 #10

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

Similar topics

51
by: Noam Raphael | last post by:
Hello, I thought about a new Python feature. Please tell me what you think about it. Say you want to write a base class with some unimplemented methods, that subclasses must implement (or...
77
by: nospam | last post by:
Reasons for a 3-tier achitecture for the WEB? (NOTE: I said, WEB, NOT WINDOWS. DON'T shoot your mouth off if you don't understand the difference.) I hear only one reason and that's to switch a...
65
by: perseus | last post by:
I think that everyone who told me that my question is irrelevant, in particular Mr. David White, is being absolutely ridiculous. Obviously, most of you up here behave like the owners of the C++...
1
by: Tony Johansson | last post by:
Hello! I'm reading about design pattern adaptor in the GOF book and there is something that sounds strange. When you use the adaptor design pattern you have these participants. *Target -...
0
by: Tony Johansson | last post by:
Hello! I'm reading about design pattern adaptor in the GOF book and there is something that sounds strange. The text below each participant is the book explanation for each participant. I...
9
by: phl | last post by:
hi, I am kind of confused aobut interfaces and abstract classes. In short as I understand it, an interface is like a contract between the class and the interface, so that certain funtions must...
12
by: SStory | last post by:
3rd time trying to post this but never see it in the list: =================================== In VB.NET, am doing the following with my MDI app.. Please advise if I am going about this wrong...
4
by: Rulin Hong | last post by:
According to OO, interface is just a bunch of definitions, no implementation at all. It's also true when we write our own code in .NET. But I find every interface provided by .NET has specific...
4
by: David Zha0 | last post by:
Hi, "when we call a virtual method, the runtime will check the instance who called the method and then choose the suitable override method, this may causes the performance drop down", is this...
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: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
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...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.