3

Yes, this problem again...

I have designed a batch system which calls notify method of ActionService and within notify method, depends on how it is called, there is a call to create method of batch service.

Example code blocks looks like this;

@Service
public class BatchService{
  private final BatchRepository batchRepository;
  private final ActionService actionService;

  public Batch create(Batch batch){
     return batchRepository.save(batch);
  }

  public void triggerNotifiers(){
     ...
     actionService.notify(...);
     ...
  }
} 


@Service
public class ActionService{
  private final ActionRepository actionRepository;
  private final BatchService batchService;

  public void notify(...){
     ...
     if(/*some special cases*/)
         batchService.create(...);
     ...
  }
} 

The functionality of batch service is to call notify method of Action service. Action service can create future notifiers depends on the incoming notification data.

So they are pretty dependent to each other.

Do you think is there a better way/logic/design to do this?

1 Answer 1

1

While I was writing the question, I figured out a way to do it:

@Component
public class Batch{
  private final BatchService batchService;
  private final ActionService actionService;

  public void triggerNotifiers(){
     ...
     batchService.findProperBatch(...);
     actionService.notify(...);
     ...
  }
} 

@Service
public class BatchService{
  private final BatchRepository batchRepository;

  public Batch create(Batch batch){
     return batchRepository.save(batch);
  }

  public Batch findProperBatch(...){
     ...
     return batch;
  }

} 

@Service
public class ActionService{
  private final ActionRepository actionRepository;
  private final BatchService batchService;

  public void notify(...){
     ...
     if(/*some special cases*/)
         batchService.create(...);
     ...
  }
} 

Please dont hesitate to share your ideas, if you have better/alternative solutions.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.