Click or drag to resize

Properties vs. Methods

One of the most fundamental design decisions driver developers face is whether to expose a particular driver capability as a method or as a property. The decision is not always clear cut. This topic will provide some prescriptive guidance on when one might choose to expose a property instead of a method, and vice versa.

Note Note

For purposes of this discussion, we will use the IVI-COM terminology -- method and property, as opposed to the IVI-C terminology function and attribute.

When to use a method

  • If the execution of the capability is going to take an extended or indeterminate amount of time, then exposing the capability as a method would be more consistent with the "principal of least surprise". Most users instinctively expect properties to execute fairly quickly and in constant time.

  • If an array of values needs to be read or written, then a method must be used. Array-type properties are not allowed, as per the IVI specifications.

  • An operation that performs a measurement, or operation, or significantly changes the state of the instrument should be exposed as a method.

  • If there are parameters associated with the capability, then it is usually best to use a method. Properties with parameters (known as parameterized properties) can be used, but the way in which these properties are accessed in various IDEs can be somewhat confusing for end users. For instance, C# always exposes parameterized properties as a pair of get_propName/set_propName accessor methods, even though the driver exposes a property. Even LabVIEW® interprets parameterized properties as methods -- forcing the developer to use an Invoke Node, which is for methods, instead of the Property Node that LabVIEW programmers expect to use when dealing with properties. In addition, it is very important to realize that parameterized properties are not supported at all in IVI-C drivers.

When to use a property

  • If the capability logically represents a setting within the instrument, such as the frequency or bandwidth, then it should be exposed as a property.

  • If the capability executes quickly and in fairly constant time, then it is a candidate for being exposed as a property.

  • If the data type is scalar (not an array), then it is a candidate for a property.

    Important note Important

    Arrays should never be exposed via properties. Array-type properties are explicitly prohibited by the IVI specification IVI-3.4: API Style Guide.

See Also

Download a complete CHM version of this documentation here.