Activity Forums Salesforce® Discussions How does Salesforce Lightning framework support Inheritance?

  • shradha jain

    Member
    July 27, 2018 at 7:42 am

    In lightning component when you want to create a component that can be extended you must set a value of true for the extensible attribute of the aura:component. By default, components are not extensible, just like Apex classes are not.When a component extends another component it inherits all of the helper methods and attributes. It also has the ability to call super component controller actions. All event handlers in the super component are inherited by the sub component. Additionally, they can both handle the same event, but the ordering of handler execution is not defined (kind of like multiple Apex triggers on a single object).

  • shariq

    Member
    September 18, 2018 at 7:43 am

    Hi,

    Lightning framework also support component inheritance in same way as it is supported in Apex.
    You can mark any component as extensible means component can be inherited by any component. Inheritance allows us use attributes and javaScript functions of extensible component in all inherited components.

    Thanks

  • Parul

    Member
    September 24, 2018 at 2:33 am

    HI

    Inheritance, The perfect way to create Code Reusability and Extensibility!!
    With this blog, we will learn how you can leverage the inheritance in Lightning Component. You need to follow below steps:

    Create a Base Component (The component that you will inherit). Make you Base component extensible using extensible=”true”. Define the body of Base component.
    Create a controller or helper or both for your base component.
    You must put {!v.body} inside your base component’s code. This will allow your base component to handle the events generated by Sub Components.
    In your Sub Component definition extend base component. Like extends=”namespace:baseComponentName”
    Use attributes of Base component in the similar way as you do for the normal component like {!v.baseComponentAttributeName}
    Call controller method of Base component directly from Sub component like {!c.baseControllerMethodName}
    Call helper method of Base component from helper/controller of Sub component like helper.baseHelperMethodName(params);

     

    Thanks

Log In to reply.

Popular Salesforce Blogs

Popular Salesforce Videos