开发者

is the Interface on its way to be obsolete soon?

as I found, an abstract class is an interface when it has zero implementation in it. am I right开发者_StackOverflow ?

then why there are interface classes in some languages, I mean C++ doesnt have an interface.

is it going to be obsolete someday soon ?


a single class can be inherited from only one class. however multiple interfaces can be applied on a single class. abstract classes cannot replace interfaces.


C++ does not have interfaces because it supports multiple inheritance, which C# does not. C# provides interfaces to get around this hurdle, so no, interface will not become obsolete.


Interface are present in language such as Java in order to supply to the lack of multiple inheritance. For this reason the language provide the possibility of inheritance from just one base class, but guarantee the possibility to implement different interfaces.


No, because interfaces have a property that abstract classes with only abstract methods (or any other kind of class) do not: a class may implement arbitrarily many interfaces, while a class may only inherit from one other class. So if you take all of your interfaces and turn them into abstract classes, you will never be able to make a class "implement" more than one "interface".

It can be noted, however, that your observation is correct in certain other languages than C#. For instance, in C++, there is no separate interface construct; "interfaces" in C++ are abstract classes with only abstract methods.


C++ doesn't have special syntax for an interface, e.g. an interface keyword because that just happens to be the design decision taken by the language designer. But C++ does indeed offer full support for interfaces.

Interfaces are not going to become obsolete. In fact the technique of using interfaces is becoming more and more widely used.


C++ does not have interfaces because unlike Java it allows multiple inheritance. Which in a way complicates things.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜