Oliver Twesten
February 27th, 2004, 11:25 AM
Hi
This is a general design question.
Say I want to implement some class member functions that perform long term calculations that should be able to report progress. The functions should not use operating system specific code as far as possible, especially, the type of progress report should not be determined!
We may assume a simple "for" loop with "sleep" statements here.
The progress should be displayed in a simple progress dialog that should be reusable for many of such progress reporting functions and offers a "break" button and a status text besides the progress control. The implementation of this dialog is naturally operating system dependent.
The thread should be started by a GUI command from a menu or button on a dialog or whatever.
I know that there are several ways how this can be implemented. I'd like to hear your opinion how this is best implemented. Maybe there are well known good design patterns?
Examples:
1) GUI-command handler creates a (nonmodal) progress dialog, starts the thread and passes the dialog handler to the thread (OS-dependent). GUI must check how long the thread is running. Notification of thread termination is not designed.
2) GUI-command handler creates an OS-specialized progress class (a specialization of a basic progress class that provides virtual functions) that in turn creates the (nonmodal) progress dialog and provide capabilities to send thread-termination notification messages back to e.g. the main application window. GUI-command hander creates the thread and passes a pointer to the specialized progress class to the thread.
3) (ugly!) GUI-command creates modal thread dialog and passed pointer to thread function that should be started. The modal dialog in turn starts the thread and passes its dialog handle (OS-dependent). Thread is responsible for ending modal progress dialog.
Thank you for your ideas
Oliver.
This is a general design question.
Say I want to implement some class member functions that perform long term calculations that should be able to report progress. The functions should not use operating system specific code as far as possible, especially, the type of progress report should not be determined!
We may assume a simple "for" loop with "sleep" statements here.
The progress should be displayed in a simple progress dialog that should be reusable for many of such progress reporting functions and offers a "break" button and a status text besides the progress control. The implementation of this dialog is naturally operating system dependent.
The thread should be started by a GUI command from a menu or button on a dialog or whatever.
I know that there are several ways how this can be implemented. I'd like to hear your opinion how this is best implemented. Maybe there are well known good design patterns?
Examples:
1) GUI-command handler creates a (nonmodal) progress dialog, starts the thread and passes the dialog handler to the thread (OS-dependent). GUI must check how long the thread is running. Notification of thread termination is not designed.
2) GUI-command handler creates an OS-specialized progress class (a specialization of a basic progress class that provides virtual functions) that in turn creates the (nonmodal) progress dialog and provide capabilities to send thread-termination notification messages back to e.g. the main application window. GUI-command hander creates the thread and passes a pointer to the specialized progress class to the thread.
3) (ugly!) GUI-command creates modal thread dialog and passed pointer to thread function that should be started. The modal dialog in turn starts the thread and passes its dialog handle (OS-dependent). Thread is responsible for ending modal progress dialog.
Thank you for your ideas
Oliver.