Activity Forums Salesforce® Discussions What is the use of interfaces(in apex classes)?

  • shariq

    Member
    September 22, 2018 at 11:18 am

    An interface resembles a class in which none of the strategies have been executed—the technique marks are there, yet the body of every strategy is void. To utilize an interface, another class must actualize it by giving a body to the greater part of the techniques contained in the interface.

    Interfaces can give a layer of reflection to your code. They isolate the particular execution of a technique from the announcement for that strategy. Thusly you can have distinctive usage of a strategy in view of your particular application.

    • This reply was modified 6 years, 3 months ago by  shariq.
  • Parul

    Member
    September 22, 2018 at 12:45 pm

    Hi

    Reasons to use an interface:

    Behavior Contract - A common method is needed on otherwise unrelated objects. The implementation of that method could be significantly different. As such, there is little benefit in inheriting the implementation (behavior).
    Coupling - If code is only dependent on the interface then it is easier to change the implementation, as there no/fewer references to a specific class. E.g. I can change the way a plane flys without any risk of making birds fall out of the sky.

     

    Thanks

Log In to reply.

Popular Salesforce Blogs

Popular Salesforce Videos