Home > Enterprise >  Adding progress bar to calculation
Adding progress bar to calculation

Time:01-07

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?

CodePudding user response:

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.

  • Related