Author:Peter Gummer

Date:2014-06-07T07:34:25.000000Z


git-svn-id: https://svn.eiffel.com/eiffel-org/trunk@1379 abb3cda0-5349-4a8f-a601-0c33ac3a8c38
This commit is contained in:
pgummer
2014-06-07 07:34:25 +00:00
parent bb0432869e
commit f77c35d8ea

View File

@@ -4,16 +4,12 @@
[[Property:uuid|d25e2dc7-7a95-c13a-bfa2-ceb42a084fa6]]
__NOTOC__
=Description=
A feature that has too many arguments should be avoided since it makes the class interface complicated and it is not easy to use. The feature arguments may include options, which should be considered to be moved to separate features.
Interfaces of features with a large number of arguments are complicated, in the sense for example that they are hard to remember for the programmer. Often many arguments are of the same type (such as INTEGER). So, in a call, the passed arguments are likely to get mixed up, too, without the compiler detecting it.
Arguments where in most of the cases the same value is passed--the default value--are called options. As opposed to operands, which are necessary in each feature call, each option should be moved to a separate feature. The features for options can then be called before the operational feature call in order to set (or unset) certain options. If a feature for an option is not called then the class assumes the default value for this option.
A feature that has too many arguments should be avoided since it makes the class interface complicated and is not easy to use. The feature arguments may include options, which should be considered to be moved to separate features.
:{| class="doctable"
|-
| '''Scope'''
| Instruction
| feature
|-
| '''Status'''
| Enabled
@@ -33,18 +29,17 @@ Arguments where in most of the cases the same value is passed--the default value
=Example of violation=
<e>my_document.print (printer_name, paper_size, color_or_not, postscript_level, print_resolution)
<e>my_document.print (printer_name, paper_size, postscript_level, print_resolution)
</e>
=Recommendation=
Replace left or right side with something else than the other element.
Detect arguments that are really options and create procedures to set them.
In the example, one could write:
<e>
my_document.set_printing_size (paper_size)
my_document.set_color
my_document.print
my_document.set_paper_size (paper_size)
my_document.set_postscript_level (postscript_level)
my_document.set_print_resolution (print_resolution)
my_document.print (printer_name)
</e>
{{SeeAlso | [[CA071 - Self-comparison]]}}