dimanche 13 août 2017

AspectJ vs DynamicProxy vs Nothing for a simple facade over an existing class

I have a simple interface DataService with ~20 methods which has multiple concrete implementations.

I am modifying a couple of implementations for 7-8 APIs. The modification is pretty consistent in the sense that I have to perform additional checks and route the call to specific implementation or it might get routed to another implementation depending on that check.

There are a couple of ways I think it could be achieved:

  1. AspectJ which always executes the condition but there are some complexities as different APIs could have different conditional parameters to work on and Aspect will not be super clean. But it will all still be at one place.

  2. DynamicProxy while calling the methods and it seems similar to above.

  3. Simple wrapper class which is simple, easy to understand but has a lot of boiler plate to it. This is simple wrapper I am talking about:

    public class ConcreteImplementation1Wrapper extends DataService {
    
        DataService concreteImplementation1;
    
        DataService nextConcreteImplementation;
    
        Condition condition;
    
        @Override
        public void setNextChain(DataService nextConcreteImplementation) {
                 this.nextConcreteImplementation = nextConcreteImplementation;
        }
    
        @Override
        @Transactional(value = "annotationDrivenTransactionManager", propagation = Propagation.REQUIRED)
        public void deleteObject(String accountId, String objectName, Context activityContext {
                if (condition(objectName)) {
                    concreteImplementation1.deleteObject(accountId, objectName, activityContext);
                } else {
                    nextConcreteImplementation.deleteObject(accountId, objectName, activityContext);
                }
    }
    
    

    }

Which approach seems reasonable for such cases?

Aucun commentaire:

Enregistrer un commentaire