Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Foo
- {
- //Registra os eventos 'baz'
- private array baz[];
- //Registra os eventos 'bar'
- private array bar[];
- //Variavel de exemplo
- private int status;
- public Foo()
- {
- }
- public on(string name, Function func)
- {
- switch (name) {
- case 'baz':
- baz.push(func);
- break;
- case 'bar':
- baz.push(func);
- break;
- default:
- throw new InvalidEventException;
- }
- }
- public changeFoobar(int value)
- {
- //Se o valor for igual ao anterior não dispara os eventos
- if (status != value) {
- status = value;
- trigger('bar');//Dispara 'bar' quando altera o 'status'
- }
- }
- /*dispara os eventos de um tipo especifico*/
- protected trigger(string name)
- {
- array evts[];
- switch (name) {
- case 'baz':
- evts = baz;
- break;
- case 'bar':
- evts = bar;
- break;
- default:
- }
- for (int i = 0; i < evts.length; i++) {
- evts[i].call(); //Chama a função
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement