I am working on a project. I am trying to implement the core as independent jar file which can be run from command line or even a windows service. The core would be responsible to keep track couple of files and send some notification emails. The question is, what would be the best idea to keep GUI totally independent?
The GUI needs following interation with the core
- send list of files
- receive notifications from core regarding how much those files has been processed
- receive status notifications regarding files i.e. SEND/Processing/Failed etc to be displayed in GUI
- receive information if there is incoming messages from core
I had this software developed in Delphi and C. C was used to code the core logic and using Windows Messages and Callbacks, i registered Delphi GUI on C dll/service. I am confused how to implement it in java.
- Observer pattern?
- Small client/server communication between core and gui?
P.S:
The reason i am discussing it here is to learn and explore better design for such softwares when coded in Java. I ain’t asking for Observer Pattern documentation or client server architecture. There could be other possible means which i am not aware of. So I am looking forward to any idea, design or framework.
Oberserver Pattern is really the correct answer for three out of your 4 use cases.
On the level of your description you might have the following interface implemented by your core:
The listeners interfaces will look really similar to this one
ProgressEvent (and the other Event classes) should be value objects, e.g.
You probably want your core and your gui to run in different threads. Otherwise your GUI would not react to any events while the core is running. Since the core shouldn’t know anything about the GUI the handover between threads should be done by the GUI, i.e. the listeners should take care to use
SwingUtilities.invokeLaterorinvokeAndWaitin order to update the GUI.