Take the 2-minute tour ×
Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. It's 100% free, no registration required.

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?

share|improve this question
1  
No, it's the other way around : not every abstract class is an interface. –  georgesl Nov 1 '12 at 16:06
1  
Are you talking about an "interface" as in a C# interface? Or do you mean the more generic form, like "the steering wheel and pedals in your car are an interface"? –  Scott Whitlock Nov 1 '12 at 16:06
    
interface like in interface in C#, C++, Delphi, Java and all the others oop languages –  JustMe Nov 1 '12 at 16:09
    
Java 8 introduced interfaces with default implementations. So you may have interface that is not-abstract, i.e., have all methods implemented in a default way. –  dzieciou Nov 1 '12 at 17:13
2  
It depends on what your friend means by "interface". Anything that can be used has an interface whether it's concrete or abstract. A concrete Chair has an interface where you sit in it. But if he means the c# keyword then he is wrong, as that's always abstract. If he designs his own language that allows him to use the interface keyword that way then he is correct. –  mike30 Nov 1 '12 at 17:16
show 1 more comment

6 Answers

up vote 7 down vote accepted

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.

share|improve this answer
3  
An API is an interface. I'm pretty sure they usually provide concrete methods –  Useless Nov 1 '12 at 16:02
1  
@Useless - as JustMe answered in a comment on the original question, he/she specifically means "interface" in the technical sense within a language like C#, not in the sense of an "API". –  Scott Whitlock Nov 1 '12 at 16:26
    
What about interface in sens of an "API"? –  JustMe Nov 1 '12 at 17:25
add comment

No.

Interface from simple definition is abstraction of API that class can implement. If it is not abstract, then it is not an interface.

share|improve this answer
1  
So how would you call interfaces in Java 8 with default implementation? Java 8 introduced interfaces with default implementations. So you may have interface that is not-abstract, i.e., have all methods implemented in a default way. –  dzieciou Nov 1 '12 at 17:16
add comment

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:

  • polymorphism: you wish to hide multiple different types or behaviours behind a description of the things they have in common. In this case, the interface should be probably abstract
  • implementation: you wish to hide the details of a complex system behind a unifying abstraction. In this case there may never be more than one implementation, so the interface can itself be concrete
share|improve this answer
    
I don't think neither things you describe can be called an interface. –  Euphoric Nov 1 '12 at 16:03
    
Case 1 is an Abstract Base Class, which is reified in several languages as something called an Interface. Case 2 is something like an Application Programming Interface –  Useless Nov 1 '12 at 16:04
    
This is correct. However I get a feeling the question is about class interfaces, which technically can't be non abstract, so perhaps you should clarify in your answer that although the general notion of interface can be non abstract, the class interface structure can't. (you already mention all this, just make the distinction between concept and structure a bit clearer) –  Yannis Rizos Nov 1 '12 at 16:38
1  
Java 8 introduced interfaces with default implementations. So you may have interface that is not-abstract, i.e., have all methods implemented in a default way. –  dzieciou Nov 1 '12 at 17:15
add comment

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.

share|improve this answer
add comment

Depends much on what meaning your friend gave to the word interface.

Interface as the concept of an abstract contract on methods/properties


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.

Interface as a contract on the description of facilities provided and their semantics


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.

share|improve this answer
add comment

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.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.