When do we use extendable components and Interfaces in Salesforce Lightning Framework?

It’s purely the architectural need that decide when to use when. Also the answer to this question lies in the difference between them and lets jump into them quickly.

Difference #1

  • We need to use an attribute extensible="true" in a Lightning component and then it can be extendable by any other component.

  • We need to use <aura:interface> to create a Interface and not <aura:component />

Difference #2

  • When we extend a component, we cannot extend more than one parent component.

  • Where as in an interface, we can implement more than one Interface.

Difference #3

  • When we extend a component, <aura:set /> is used in the sub component to set a value to the attribute that is inherited from the super component.

  • Where as in an interface, to set the value to an attribute, we need to re-define the attribute in the Lightning component and set value using its default attribute.

Difference #4

  • When we want to create a custom interfaces, we can only use the two tags mentioned below and also an interface starts with <aura:interface> tag.

    1. <aura:attribute> tags to define the interface's attributes.
    2. <aura:registerEvent> tag to register the events that it may fire.
      An Interface will not have any implementation of the code in it.
  • Thats not the case when we try to create a extendable Lightning component.

By now you would have got a clean understanding about which concept to use when, in your projects.

Subscribe with your email-id to make sure you dont miss any of our posts.

Interested in learing more things like this? You can register here

Not interested in reading blogs? Tweet me @kkteja if you want me to make a video on this.