On 24/09/15 19:30, John Dennis wrote:
What do you think about this design pattern? I think it might easily
solve the issue and simplify the code.
* Pages have a property indicating if preexisting transaction is
mandatory, it defaults to False.
* Any page that requires a preexisting transaction sets the property to
True.
* The Page class implements a method to get a transaction, it calls a
Page class method (which can easily be overridden) to get the
transaction (any page which permits a transaction to be passed
elsewhere, e.g. in the Referer would override the method). If no
transaction is found it checks the property to see if a preexisting
transaction is mandatory, if so it raises an error otherwise it creates
a new transaction and returns it.
How does that sound? This would replace Page.get_valid_transaction() and
direct calls to the Transaction constructor.
Works for me, but be careful and do a lot of testing, we ended up w/ two
functions because they were needed at the time, and they needed to
behave differently in exactly the way they do.
Of course if we change all callers we can change semantics but we can't
change the behavior.
Sorry that I do not recall the exact trouble spot we went through.
Simo.
--
Simo Sorce * Red Hat, Inc * New York