Page 1 of 1

handling data/msg transfer between multiple functions/layers

Posted: Sun Jun 03, 2007 5:27 pm
by raghavan20
i am facing trouble communicating among layers or among many functions since i use arrays predominantly for intercommunication. is there a better way around. i explain more with two real examples. thanks for reading.

example 1:

in a MVC model, we used to separate things as controllers,

renders & model(including db wrappers). lets say we are

dealing with saving a card.

1. render that displays result
2. controller calls up methods in model
3. model does the work; may involve using wrappers to

persist save card data

the controller gets control, calls model and model saves

data using wrappers. the wrapper says the model back whether

the data is saved or not
1. data saved successfully
2. data could not be used due to data error (when error

thrown by mysql or other db)
3. data not altered

based on the messages from wrapper, the model has to compose

messages like
1. card data is the same
2. card data successfully
3. card data invalid

the controller has to now compose a elaborate message to

send to the render so that it can displayed to the user based on message from model. for this kind of communication, i normally tend to arrays between each layer and if exceptions/cases grow, the arrays become complex and hard to handle. is there is any better of handling this?


example 2:
i have an edi application. the edi application places orders

with suppliers. depending on supplier, different format/type of order file will be generated. lets say there exists these

many functions
1. renders
2. controller
3. supplier manager
4. edi manager

controller selects the supplier. supplier manager gets

configuration variables and also gets orders. edi manager

processes orders and generates x12 file.

the edi manager returns
1. file content
2. order ids successfully processed for the order file


the supplier managers says the following. has two cases:
if file could not be generated
1. result: whether process was successful
2. message: if error during file generation, reports error

message
3. return: null

if file generation was successful
1. result: true
2. message: file generated successfully
3. return: array( filePath=>, rowIdArray=>,

moreInfo=>(description of file-order file from supplier 1)

)


controller composes messages for renders:
1. orders that are affected using passed rowIdArray
2. displays moreInfo
3. displays the file path and allows to download the file

here also you could see there are lot of messages passed between starting to layer to final layer in the application. but since i increasingly use arrays, it is getting more difficult to manage within the application. but you could say, i make these arrays well-defined for functions, say may be predefined api but still using arrays are tougher solutions. any alternative around?