0

I am looking at the fflib-apex-common-samplecode, and I see that the AccountsSelector uses an interface IAccountsSelector, see below:

  public class AccountsSelector extends fflib_SObjectSelector implements IAccountsSelector
    {
        public static IAccountsSelector newInstance()
        {
            return (IAccountsSelector) Application.Selector.newInstance(Account.SObjectType);
        }
        // ...
    }

Source

Which are the benefits of using the interface IAccountsSelector? Why not just using:

  public class AccountsSelector extends fflib_SObjectSelector
    {
        public static AccountsSelector newInstance()
        {
            return Application.Selector.newInstance(Account.SObjectType);
        }
        // ...
    }

1 Answer 1

4

It was implemented with interfaces to allow dependency injection (for example, for mocking). This way you can create other classes that implement the interfaces and use them (inject them) in runtime. For example, you can use mock classes when executing unit tests to create more pure unit tests.

https://quirkyapex.com/2017/12/03/fflib-application-structure/

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .