Pass inter-objects parameters by name

Share this topic:



Link to this posting

Postby Ursego » 19 Feb 2013, 22:28

Passing parameters between objects, use one of methods where parameters are accessed by a mnemonic name, not by a meaningless index of an array.

...as it unfortunately happens when programmers decide to use an NVO or a structure with arrays having numeric (by index) access to the elements. Here is an example of that very BAD approach:

Code: Select all
lstr_parm.long_args[1] = il_emp_id
lstr_parm.long_args[2] = il_dept_id
lstr_parm.string_args[1] = is_first_name
lstr_parm.string_args[2] = is_last_name
lstr_parm.date_args[1] = id_birth_date
lstr_parm.date_args[2] = id_hire_date

The index-by approach is extremely inconvenient and terribly bugs-prone!!! Imagine, that a window can be open from different places in the application, with a similar, but unique sets of parameters in each case. And even more: some of these sets (or all) can be changed in the future... Brrrrr!!!!.

There are a few methods to pass parameters where they are accessed by a mnemonic name.

Method #1 - PB structures individually created for each parameters set.

Advantage:
@ Convenience working with nested data structures (you can use dot notation to access them directly - like lstr_order.str_order_header.order_date).

Disadvantages:
@ You have to create a custom structure for each individual case making PBLs crowded.
@ Extra maintenance efforts: to change passed sets of data, you have to check out, change and check in each structure.

Method #2 - a universal parameters transportation class serving the whole application (like this).

Advantages:
@ No need to create tens or even hundreds of custom structures or NVOs for each individual case, so the PBLs will be less crowded.
@ Less maintenance efforts - you don't have to check out, change and check in that class when passed sets of data are changed - you only change the sending and the receiving scripts.

Disadvantage:
@ Less convenience working with nested data structures (you have to unpack passed structures and classes into variables before using their members).
User avatar
Ursego
Site Admin
 
Posts: 112
Joined: 19 Feb 2013, 20:33

Return to Elegant Code

Who is online

Users browsing this forum: No registered users and 1 guest


Pass inter-objects parameters by name

Share this topic:


If you think that this site is not too bad, please LIKE it in Facebook. Thanks!





cron
free counters

eXTReMe Tracker