(Using Python 3.2, though I doubt it matters.)
I have class Data
, class Rules
, and class Result
. I use lowercase to denote an instance of the class.
A rules
object contains rules that, if applied to a data
object, can create a result
object.
I'm deciding where to put the (rather complicated and evolving) code that actually applies the rules to the data. I can see two choices:
Put that code inside a class
Result
method, sayparse_rules
.Result
constructor would take as an argument arules
object, and pass it ontoself.parse_rules
.Put that code inside a new class
ResultFactory
.ResultFactory
would be a singleton class, which has a method, saybuild_result
, which takesrules
as an argument and returns a newly builtresult
object.
What are the pros and cons of the two approaches?