Reputation: 1105
I have a class that does a complex calculation which may take a long time. I'd like to add a progress bar with Abort button. However, I would like to avoid mixing calculation code with GUI code if possible.
Are there any good design patterns for this?
Upvotes: 0
Views: 72
Reputation: 2147
The relevant design pattern is the Observer pattern: your class doing a calculation is the "subject", it maintains a list of Observers, implementing a common Observer interface, and when its state changes (i.e. the amount of progress has changed), it notifies each observer via an update() call.
Upvotes: 2