Activity › Forums › Salesforce® Discussions › What is the use of interfaces(in apex classes)?
Tagged: Behavior Contract, Coupling, Salesforce Apex Class, Salesforce Interface, Salesforce Objects
-
What is the use of interfaces(in apex classes)?
Posted by Aman on September 22, 2018 at 11:17 AMWhat is the use of interfaces(in apex classes)?
Parul replied 7 years, 7 months ago 3 Members · 2 Replies -
2 Replies
-
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 7 years, 7 months ago by
shariq.
-
This reply was modified 7 years, 7 months ago by
- [adinserter block='9']
-
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.