There are many observers for a event.
Observers need to process event in specific order.
Observers belong to different modules. they are all plugin/mods.
how can i manager the order in an elegant way.
Way 1:
declare the priority in a config file. maybe:
observers = {
"modA",
"modB",
}
but this is not plugable. i have to declare all before application startup.
Way 2: every observer define a interface:
//file a
function modA:getPriority()
return 99
end
//file b
function modB:getPriority()
return 98
end
now priority is decided on running time. And different observer live in different source file .
but i can not figure out who has lower priority than modA easily. i need to search all source directory.
if i have a new mod that need in middle of modA and modB, i have to write 98.5...
so, is there someway better than my ways.
Aucun commentaire:
Enregistrer un commentaire