Newer Version Available

This content describes an older version of this product. View Latest

Interfaces

Object-oriented languages, such as Java, support the concept of an interface that defines a set of method signatures. A class that implements the interface must provide the method implementations. An interface in Java can't be instantiated directly, but a class that implements the interface can.

Similarly, the Lightning Component framework supports the concept of interfaces that define a component's shape by defining its attributes.

An interface starts with the <aura:interface> tag. It can only contain these tags:

  • <aura:attribute> tags to define the interface's attributes.
  • <aura:registerEvent> tags to define the events that it may fire.

You can't use markup, renderers, controllers, or anything else in an interface.

To use an interface, you must implement it. An interface can't be used directly in markup otherwise. Set the implements system attribute in the <aura:component> tag to the name of the interface that you are implementing. For example:

1<aura:component implements="mynamespace:myinterface" >

A component can implement an interface and extend another component.

1<aura:component extends="ns1:cmp1" implements="ns2:intf1" >

An interface can extend multiple interfaces using a comma-separated list.

1<aura:interface extends="ns:intf1,ns:int2" >

Use <aura:set> in a sub component to set the value of any attribute that is inherited from the super component. This usage works for components and abstract components, but it doesn't work for interfaces. To set the value of an attribute inherited from an interface, redefine the attribute in the sub component using <aura:attribute> and set the value in its default attribute.

Note

Since there are fewer restrictions on the content of abstract components, they are more common than interfaces. A component can implement multiple interfaces but can only extend one abstract component, so interfaces can be more useful for some design patterns.