<p>I've got a situation where I have a main form that pops up an advanced configuration form that just has half a dozen matched check boxes and combo boxes to select some advanced options (the check boxes to enable/disable, the combo to select a media if enabled).</p>

<p>If I just pass the individual settings for the check and combo boxes in to the constructor for the dialog that's obviously a dozen arguments, which seems a bit excessive.</p>

<p>My other obvious option would be since in the main form these settings are stored in a large IDictionary with all the other main form settings I could just pass this dictionary in and fetch it back afterward with the updated values, but my understanding is that this wouldn't really be very good coding practice.</p>

<p>Am I missing a good way to do this that is both efficient and good coding practice?</p>

<p>(this particular code is in C#, although I have a feeling a general solution would apply to other languages as well)</p>

[{'answer_id': 40142, 'author': 'Rob Cooper', 'author_id': 832, 'author_profile': 'https://Stackoverflow.com/users/832', 'pm_score': 4, 'selected': True, 'text': '<p>I personally would create a carrier object to store the values. You then get the nice intellisense for it, and changes to it would be quite straightforward. It would also be faster than dictionary lookups for parameter values. And of course, you get type safety. :)</p>\n'}, {'answer_id': 40149, 'author': 'Chris Marasti-Georg', 'author_id': 96, 'author_profile': 'https://Stackoverflow.com/users/96', 'pm_score': 0, 'selected': False, 'text': '<p>Something like this should be good:</p>\n\n<pre><code>MyConfigurationDialog dialog = new MyConfigurationDialog();\n\n//Copy the dictionary so that the dialog can\'t mess with our settings\ndialog.Settings = new Dictionary(existingSettings);\n\nif(DialogResult.OK == dialog.Show()) {\n  //grab the settings that the dialog may have changed\n  existingSettings["setting1"] = dialog.Settings["setting1"];\n  existingSettings["setting2"] = dialog.Settings["setting2"];\n}\n</code></pre>\n'}, {'answer_id': 40163, 'author': 'JosephStyons', 'author_id': 672, 'author_profile': 'https://Stackoverflow.com/users/672', 'pm_score': 0, 'selected': False, 'text': '<p>I agree with Rob Cooper.  Create a class to represent your configuration, and pass that into the constructor of your form.  This will also allow you to define methods on your new "config" class like "saveSettings", "LoadSettings", etc.  That in turn should keep the code more maintainable in general.</p>\n\n<p>As an quick-and-dirty alternative, if you are saving these to a file somewhere, just pass the name of the file, and have your form read that at run-time.</p>\n\n<p>The first option really is the way to go though, IMO.</p>\n'}, {'answer_id': 40192, 'author': 'Ed Schwehm', 'author_id': 1206, 'author_profile': 'https://Stackoverflow.com/users/1206', 'pm_score': 1, 'selected': False, 'text': '<p>You could go with Rob\'s solution; that\'s the prettiest for development. Your "carrier object" could contain the entire IDictionary and have typed properties to help intellisense. The properties could update the IDictionary. When you\'re done, you can pass the carrier object back and fetch the IDictionary directly from it. </p>\n\n<p>For example, if your dictionary had key/value pair "FirstEnabled"/boolean, you could do this:</p>\n\n<pre><code>class ContainerObject\n{\n    public IDictionary&lt;object, object&gt; _dict;\n    public ContainerObject(IDictionary&lt;object, object&gt; dict)\n    {\n        _dict = dict;\n    }\n\n    public bool FirstEnabled\n    {\n        get { return (bool) _dict["FirstEnabled"]; }\n        set { _dict["FirstEnabled"] = value; }\n    }\n}\n</code></pre>\n\n<p>You can change the member "_dict" to private or protected and have a accessor function if you want. </p>\n'}]
['https://Stackoverflow.com/questions/40132', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/1512/']