Pass inter-objects parameters by name

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. 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 not absolutely identical 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.

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

@ 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).

@ 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.

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

IF you want to ((lose weight) OR (have unbelievable (brain function AND mental clarity))) THEN click:

free counters

eXTReMe Tracker