oop - PHP Design Pattern Advice - many dependant steps that rely on results from previous steps -
short version:
how collect results of complicated operation spread on several objects?
long version:
i developing data exchange system push customer orders 1 system system. done via api , unfortunately require 12 individual steps completed in sequence before order can reported transferred.
although each step can (and has) been broken down individual units of code, each step has completed in sequence , steps depend on result previous steps.
is there suitable design pattern or combination of patterns fit particular problem? if each step dependant on previous step whats best way make aware of previous steps result.
i thinking of composite/macro command design or perhaps modelling orderpush process finite state machine although hoping keep more simple.
this question system design there no need go detail on api or how works , i'm expecting pointed in right direction.
the process read relevant data local system , push remote system via xmlrpc.
the steps are:
- create customer
- create order (header record)
- create order lines
- confirm order (this creates invoice)
- find invoice
- confirm invoice
- create payment
- find journal item (journal item relates invoice payment line can tied invoice)
- create payment line
- confirm payment
each step single xmlrpc call either succeed or fail. , crux of it. if customer failed created none of other steps work. if order failed created other steps either fail or not able tie (i.e. should stop execution if previous step fails).
so has got tips?
for interested, did stumble across design pattern suited needs.
my question have been condensed down simply:
how collect results of complicated operation spread on several objects?
(i have edited question)
the answer collecting parameter design pattern. http://sourcemaking.com/implementation-patterns/collecting-parameter
there not many examples in php world although not complicated concept. common sense guess thats design patterns are.
the way solved implementing each separate operation using command pattern abstracts single operation can invoke using common interface (i.e. "process()" or "run()" method).
given have 12 operations can invoke own process() method, trigger them in order , pass in generic object (called collectingparameter clarity) job record result of each operation (so collectingparameter object must returned each process() method). collectingparameter object gets passed next operation have access of results needs previous operations.
$operationlist = array(new createcustomer, new createorder, new createorderlines ... etc) $collectingparameter = new collectingparameter; foreach($operationlist $operation) { $collectingparameter = $operation->process($collectingparameter); }
errors logged , handled within various process methods leaves process() method free return collectingparameter object rather results of operation.
Comments
Post a Comment