I've been trying to build a Lightning Community where I use component inheritance and interfaces to share certain bits of functionality. For my particular use, composition wouldn't fit as well as inheritance, so that's not really an option.
As I dig into it, interfaces seem a bit pointless.
The big gotcha in this whole topic is that the blog here: https://developer.salesforce.com/blogs/developer-relations/2015/03/salesforce-lightning-components-by-example-component-extension.html no longer works as it relies on methods that have since been removed from the public API.
So, I tried a few things. I created the following interface:
<aura:interface description="A test interface">
<aura:attribute name="example" type="String" default="" description="An example attribute."/>
<aura:attribute name="exampleMethod" />
</aura:interface>
And then used it in the following component:
<aura:component implements="c:TestInterface">
</aura:component>
Shouldn't that be a compile-error? Or a run-time error? I haven't implemented the attribute or method specified in the interface.
And, then we turn to attempting to use an instance of my component. Say, I have a reference to my component elsewhere and I want to call exampleMethod() on it. I'd expect to write something like this:
if(component.instanceOf('c:TestInterface')) {
component.exampleMethod();
}
Except that, component.instanceOf() is no longer a public method in Lightning (just like getDef() from the blog above), so I can't write that.
EDIT as Christian Menzinger the correct name is isInstanceOf() and it does work, so this criticism is invalid. Which actually makes me slightly happier
So, I end up writing:
if(component.exampleMethod) {
component.exampleMethod();
}
Which seems to make the interface entirely pointless. Or, am I missing the point?