Questions tagged [interface]

An interface refers to the designated point of interaction with a component. Interfaces are applicable at both the hardware and software level. --- It also refers to the language-element `interface`, which is the sole exception to single-inheritance in Java, C# and similar languages.

An interface is the designated point of interaction with a component.

Well-defined, comprehensive, versatile but still minimal interfaces are critical for reliability, extensibility, maintainance, and compatibility.

In programming, we mostly encounter:

  • s, which consist of symbols (types (and all they might entail), functions, constants, variables, templates, namespaces and so on), and their defined behavior, which might include their own turing-complete languages.
  • s, which define the mapping of APIs to the underlying machine.
  • s, which define interactions over a connection, network, or the like.
  • And many combined ones, especially in directly interacing with a device, for example to write a device-driver.

In some languages, mostly object-oriented single-inheritance ones, an interface is a restricted type not containing any state nor instantiable by itself, and only able to inherit from (any number of) other interfaces.
A can implement any number of interfaces in addition to inheriting from a single other class (most of those languages enforce a single-root inheritance-hierarchy).
Most insist that the base-class is listed first, and some allow explicitly implementing an interfaces members, which makes them inaccessible except through an interface-pointer of that type.

The implementation of an interface varies between programming languages and environments; for e.g. C# has the following definition (Interfaces (C# Programming Guide));

Interfaces describe a group of related functionalities that can belong to any class or struct. You define an interface by using the interface keyword, as shown in the following example.

interface IEquatable<T> {
  bool Equals(T obj);
}

An interface may or may not contain or make use of any number of interfaces or their equivalent.

You can "program to the interface, not the implementation" without using any interface, as well as fail to but still use interfaces all over the place.

The [interface]-tag should should be used in conjunction with the appropriate [language]-tag(s) where applicable.

19932 questions
9
votes
4 answers

query about interfaces in Java

Lets say I have two interfaces interface A and interface B: public interface A { public int data(); } public interface B { public char data(); } interface A has a method public int data() and interface B has a method public char data(). when I…
anonuser0428
  • 11,789
  • 22
  • 63
  • 86
9
votes
3 answers

Implementing different yet similar structure/function sets without copy-paste

I'm implementing a set of common yet not so trivial (or error-prone) data structures for C (here) and just came with an idea that got me thinking. The question in short is, what is the best way to implement two structures that use similar algorithms…
Shahbaz
  • 46,337
  • 19
  • 116
  • 182
9
votes
2 answers

How to find "essential" methods to provide an interface of Ruby mixins?

The horribleness of the title of the question is what I'm trying to solve. Example: in Ruby, Enumerable is an interface in a sense that I can implement something and document it as: def myfancymethod(please_pass_me_an_Enumerable_here) but on the…
ulver
  • 1,521
  • 16
  • 29
9
votes
3 answers

What is the point of this code?

I'm reading through the source code for ASP.NET MVC3, and I came across the following inside of the code for ControllerBase: public interface IController { void Excecute(RequestContext requestContext); } public abstract class ControllerBase :…
Mike Bailey
  • 12,479
  • 14
  • 66
  • 123
9
votes
3 answers

What is a good pattern for storing implementations of an interface and retrieving specific implementations?

I am writing a simulator that has several interfaces which all simulated objects implement. The Entity interface has methods that all objects must have, such as ID retrieval and advancing the time step for the object's state. Collidable extends…
derefed
  • 679
  • 5
  • 17
8
votes
3 answers

Java interfaces - What exactly is in the contract?

I know and understand the value of interfaces in Java. You code to the interface, and then you can change your implementations without having to change any code using the interface. Often the term "contract" is used in connection with interfaces.…
dnc253
  • 39,967
  • 41
  • 141
  • 157
8
votes
0 answers

XJC superinterface and superclass only for all classes?

I'm trying to automatically implement an interface in one java class generated from a xsd file. This looks as if it could do that, but it will only add implements SomeInterface to all classes, which is completly stupid. Am I missing something or can…
Franz Kafka
  • 10,623
  • 20
  • 93
  • 149
8
votes
4 answers

Getting SuperInterfaces in java

I have been trying to do this for quite some time now and can't seem to get the desired output. What I want to do is have a class name say java.util.Vector get the: the directly implemented interfaces if java.util.Vector. the interfaces directly…
8
votes
3 answers

DBus interface properties

How do I get the list of available DBus interface properties? I am writing a script that would be tracking specific type of usb devices connections. A way to distinguish the connections to be tracked from all usb connections I guess is to check the…
Alex
  • 43,191
  • 44
  • 96
  • 127
8
votes
5 answers

Different Enum HashCode generation?

Why there are different hashCode values for each time you run a java main? Look the example code below. interface testInt{ public int getValue(); } enum test implements testInt{ A( 1 ), B( 2 ); private int value; private…
Víctor Hugo
  • 233
  • 1
  • 10
8
votes
3 answers

Abstract class or interface. Which way is correct?

There are two way for choosing between abstract class or interface. Microsoft solution and Oracle solution: Microsoft, design guideline: Do use abstract (MustInherit in Visual Basic) classes instead of interfaces to decouple the contract from…
Amir Saniyan
  • 13,014
  • 20
  • 92
  • 137
8
votes
2 answers

Keep track of all the classes that implement a particular interface?

It's difficult to explain what I really want. I have an interface which has a method getRuntimeInfo() which provides me all the runtime debug information for the variables of a class. I want to see the list of all the classes that implement this…
atmaish
  • 2,495
  • 3
  • 22
  • 25
8
votes
2 answers

Is the implementation of Delphi interface reference counting future proof

I have a helper class that will be in wide use across the application. The implementation relies on interface reference counting, the idea roughly is: ... var lHelper: IMyHelper; begin lHelper := TMyHelper.Create(some params); ...some code…
user219760
8
votes
1 answer

IL Code of an interface

I am using LinqPad and in that I was looking at the IL code(compiler optimization switched on) generated for the following Interface & the class that implements the interface: public interface IStockService { [OperationContract] double…
Pawan Mishra
  • 7,212
  • 5
  • 29
  • 39
8
votes
5 answers

C# interface and generic combination. Want to return instead of its base interface

Have stepped on my own toes with what I thought was a very simple piece of code. Code speaks better than words, so here it is. public interface IResponse { IResult Result { get; set; } } public class Response : IResponse where T :…
Arkiliknam
  • 1,805
  • 1
  • 19
  • 35
1 2 3
99
100