Apex Enterprise Pattern for universal usability

Everyone! I have a question - what if i don't want what kind of objects i will get? One day it is Accounts, next day - Opportunities, etc. Can I write Application.cls something like this?

{
    // Configure and create the UnitOfWorkFactory for this Application
    public static final fflib_Application.UnitOfWorkFactory UnitOfWork = 
        new fflib_Application.UnitOfWorkFactory(
                new List<SObjectType> {
                    SObject.SObjectType }); 

    // Configure and create the ServiceFactory for this Application
    public static final fflib_Application.ServiceFactory Service = 
        new fflib_Application.ServiceFactory( 
            new Map<Type, Type> {
                    ISObjectService.class => SObjectsServiceImpl.class});

    // Configure and create the SelectorFactory for this Application
    public static final fflib_Application.SelectorFactory Selector = 
        new fflib_Application.SelectorFactory(
            new Map<SObjectType, Type> {
                    SObject.SObjectType => SObjectsSelector.class });

    // Configure and create the DomainFactory for this Application
    public static final fflib_Application.DomainFactory Domain = 
        new fflib_Application.DomainFactory(
            Application.Selector,
            new Map<SObjectType, Type> {
                    SObject.SObjectType => SObjects.Constructor.class });
}

So all other layers will be only for SObject, as I can understand. Is it real life decision or not? Thanks)

Answers 1

  • No, you really can't write it this way. The purpose of these classes is to be replicated for each separate Application, which will have specific implementation behaviors. The fflib framework works dynamically, but it needs concrete data types at the application level.


Related Questions