vendredi 24 août 2018

Calling method one after another spring boot

I have a service which performs a certain set of operations and these operations has to be performed in a sequence like below:

class ABCService{
        @Autowired
        ContextCreator contextCreator;
        @Autowired
        ClassA classAObject;
        @Autowired
        ClassB classBObject;
        @Autowired
        ClassC classCObject;
        @Autowired
        ClassD classDObject;
        @Autowired
        ClassE classEObject;

        public void serviceMathod(Command command){
             //Command has the input data which would be need for by the operations to perform the operations
             //Using the Command object we create the context which would available to all the classes which has the operations. Basically the context object is autowired to all the classes which has the operations
             contextCreator.createContext(command);    
             classAObject.operation1();
             classBObject.operation2();
             classCObject.operation3();
             classDObject.operation4();
             classEObject.operation5();
        }
}

And the above service method is the starting point. Is there a way to clean the above code?

Piece of code which calls operations of different classes 1 by one looks weird to me. Is there any way I could use the frameworks or any design pattern to improve the code?

The application is a standalone server side application using spring boot and spring data JPA.

Aucun commentaire:

Enregistrer un commentaire