c# - Unity IOC and Factory pattern inside a large loop -
i want use factory pattern in application receive huge(500k) list , lets list,of objects , loop through it, 1 of property(seattype) decides class process list, if seat type premium handled different class , economy , on...
class bus { public seattype type { get; set; } }
since check on seat type , hence finding processor happening inside loop whats best way resolve/find instance of property has process bus?
i know can group list seat type , process it, interested know if there better way without grouping , using loop.
thanks in advance!!!
edit:
in case need processors @ 5th level, e.g. in loop calling classa.methoda , methoda calls classb.methodb , on till classe.methode.
i need processsors in classe 4 level inside loop , don't want pass dictionary of processors classa classb , on.
please help!
i use dictionary
has mapping between seattype
, processing class. , in each iteration take correct processor dictionary
.
e.g.
dictionary<steattype, iprocessor> processors = new dictionary<steattype, iprocessor>(); (int = 0; < buses.length; i++) { bus b = buses[i]; iprocessor p = processors[b]; // p.process(b); }
if don't want pass processors
class a
class e
can create helper
class singleton , holds processors
. on each level can call singleton specific processor.
or maybe when possible think looks quite better inject processors
in constructor 5 classes a
e
possible use different processor
dictionaries
on different levels ;)
Comments
Post a Comment