Friend of mine said that not every interface is abstract. I haven't chance to discuss that with him but it get me thinking of not abstract interface in any type of language.
Is there a non abstract interfaces?
Friend of mine said that not every interface is abstract. I haven't chance to discuss that with him but it get me thinking of not abstract interface in any type of language.
Is there a non abstract interfaces?
Simple answer to your question : No, your friend is wrong.
An interface provides no implementation of the methods it defines. Would it make sense if we could instantiate one of those? Of course not. Interfaces are only that, an abstraction.
This is obviously assuming that when you say interface
, you think about the interface language feature as defined by C#, Java, C++, etc with the interface
keyword. In the case your friend means an API interface, then the question does not really make sense to me. APIs may allow you to extend functionality through subclassing or by adhering to a particular contract as defined by an interface or an existing class of the system.
Yes.
The idea of an interface (ie, a description of facilities provided and their semantics) is inherently abstract.
However, the question appears to confuse this with the mechanism by which such an interface (small i) may be reified into certain languages which provide an Interface
(big i) for this purpose.
Further, there is anyway more than one thing you may wish abstract:
Depends much on what meaning your friend gave to the word interface.
So this means the Interface types provided by diverse languages (like the cited above: C#, Object Pascal (Delphi or FPC), Java, etc) so the answer is no.
In this case, the Interface is an contract on methods - without any form of implementation.
In this case, even an non-pure abstract class can be considered an interface. In this case, the designer even have how to implement default basic behavior (like throwing exceptions on non-implemented virtual methods which are not abstract) on that base class.
So, if it is the case, so yes those "interfaces" can be not abstract.
No.
Interface from simple definition is abstraction of API that class can implement. If it is not abstract, then it is not an interface.
Interfaces need not be abstract. Example:
class Foo {
public:
void printHello () {
printf("Hello");
}
};
Here Foo
is a concrete class with an interface printHello()
. Foo
is not abstract.
All above answers are correct. But this is how I understand it.
Interface
are just definitions of service. E.g. You need to book a ticket for an air travel. Its an idea/concept that you 'book a ticket'. And not worry about how it is done physically.
A Class
that implements it will define how it is done and what physical form it takes.
E.g. An Interface could be to book a ticket. You could then have various entities that provide you this service. A travel agent, online booking, or actual airline office.
They all provide the service (Interface
) to book a ticket.