I'm implementing a simple desktop application which is divided into 3 layers: UI -> service/domain -> repository.
I'm thinking about using a Mediator class so that UI layer can be notified of progress of other classes in other layers but other classes are not coupled to UI
.e.g. there's a purchase product operation. I want UI to be able to display the detail progress of purchasing a product, .i.e. it can print out on the screen the progress: - Contacting payment gateway - Finish payment - Update inventory etc
Is this an acceptable solution? Or any other suggestion?
Thank you very much
Yes, I've used a mediator before for this type of thing—specifically using guava's EventBus as the mediator.
On my current project I'm using a simplified Observer: the Observer interface has a single signal()
method (no parameters). On every event loop, the signalled components are updated.