c# - How to configure the factory to generate the object? -
maybe title not clear. let me clarify i'm trying accomplish.
i have base classes:
- baseproperties
- baseproblem
baseproperties contains data generation of math problems. example, in image above, basicadditionproperties contains addend1 , addend2, 2 objects know range of generated value represent basicadditionproblem.
so, idea.. guess supposed pass abstract class factory, , 1 should generate problem (in case basicadditionproblem).
i have read, it's recomended pass these values base class. , main doubt is, when pass object baseproperties factory, time have cast object?
or ideas can implement model scenario? or have have static factory maintain , used mapping concrete factories? in advance.

define abstract createproblem() in baseproperties class. method can used generically allow each concrete properties subclass provide own factory method.
this similar using instance of webrequest subclass , calling getresponse() on , returns coresponding subclass of webresponse.
this distributed abstract factory approach allows add property/problem pairs system because code map 2 solely contained in 2 classes.
you use full abstract factory implementation have propertyproblemfactory defines createproperties() , createproblem(). in example have additionfactory knows how create matching set. forces define additional class each property/problem pair. works best when have class uses current/selected propertyproblemfactory, creates properties it, , uses same propertyproblemfactory factory create matching problem. once let go of reference factory , solely have reference properties, harder re-locate right factory create problem. (this can addressed yet class map object types factories, complexity rises. first appoach suggested better in kind of situation).
Comments
Post a Comment