design for interruptable operations

Posted by tpaksu on Programmers See other posts from Programmers or by tpaksu
Published on 2012-12-15T21:05:03Z Indexed on 2012/12/15 23:18 UTC
Read the original article Hit count: 132

I couldn't find a better topic but here it is;

1) When user clicks a button, code starts t work,

2) When another button is clicked, it would stop doing whatever it does and start to run the second button's code,

3) Or with not user interaction, an electrical power down detected from a connected device, so our software would cancel the current event and start doing the power down procedure.

How is this design mostly applied to code? I mean "stop what you are doing" part?

If you would say events, event handlers etc. how do you bind a condition to the event? and how do you tell the program without using laddered if's to end it's process?

method1();
if (powerdown) return;
method2(); 
if (powerdown) return;

etc.

© Programmers or respective owner

Related posts about design-patterns

Related posts about control-structures