当前位置: 动力学知识库 > 问答 > 编程问答 >

objective c - Library with large number of parameters

问题描述:

I'm developing a library to be used by myself and third parties. To initialise this library I'll need to pass on a fairly large number of mandatory parameters. I don't know how many in total yet, but I'm already at 9.

I'm trying to figure out what's the best way to pass on those parameters.

1) Pass each parameter, one by one. This will become unwieldy and error prone.

2) Make available one constant per parameter and make the library require a hash table, with each constant being the key to the value.

3) Create a model object with all fields and make that available to the user.

Number 2 and 3 seem to be the best although I'm not sure I've seen any of them implemented anywhere else.

网友答案:

Your 3. looks promising.

Passing one object with all the 9 or even more values will be readable.

Also if you need to send similar kind of values you can send array or dictionary.

分享给朋友:
您可能感兴趣的文章:
随机阅读: