Let's look at our six magic questions.
- Is code included directly in my question? (See Make sure you include your code in your question below.)
- Am I an owner or maintainer of the code?
- Is it actual code from a project rather than pseudo-code or example code?
- Do I want the code to be good code? (i.e. not code-golfing, obfuscation, or similar)
- To the best of my knowledge, does the code work?
- Do I want feedback about any or all facets of the code?
For the sake of argument, we can assume that the code is embedded in the question, OP maintains the code, wants it to be good code, and wants feedback on all facets of the code.
That leaves us with just two things to ponder on.
- Is it actual code from a project rather than pseudo-code or example code?
- To the best of my knowledge, does the code work?
The prior is often referred to as "real code", so is an Interface real code? Well, it's certainly not pseudo-code. Let's also assume, again for the sake of argument, that the code in question does not contain classes or methods named Foo
, Bar
, and the like. Therefore, not being example code. That leaves just one last test to pass.
Does this code work?
To determine if code works or not, first we have to understand what it means "to work". I could not find a meta post clearly defining what working code is, so I'll refer to Meriam-Webster. Irrelevant definitions omitted.
Work intransitive verb
1 b : to perform or carry through a task requiring sustained effort or continuous repeated operations
2 : to function or operate according to plan or design
4 : to produce a desired effect or result : succeed
Definition 1b is the only place an Interface fails to meet the definition of "working code". It does indeed meet the definition of "to function or operate according to plan" and to "produce a desired effect". Which, I would argue, is our intent by asserting that code must "work" to be posted as a question here. What we really mean is that the code must be functional. It must compile and produce the intended results. An Interface creates a contract that implementing classes must abide by. They do not execute code, but that does not make them broken. That's what we really care about here. Is the code broken? No, interfaces are (obviously) not broken code by mere virtue of their nature. By that measure and logic, Interface only questions are indeed on topic.
Furthermore, Interface questions have been well received in the past. Some examples:
Update:
I am leaving this here, because I think it is important to the discussion to note that it is not the question of "working code" that makes interface only questions off-topic. It seems that I was mistaken to assert that Interfaces are not to be considered example code. This quote from rofl's answer convinced me of my logic error.
If the question supplies an interface only, then then it can only be considered to be example code, because the current implementing/interacting code does not matter, is meaningless, and has no value to the asker in the context of the question. They are looking for a design review, not a code review. They may as well draw a picture/flow-chart instead of the interface (in fact, that would probably be better....).