What guideline is violated when an API uses the prefix "set" for non-setter methods?

Master the API Design Principles Test with diverse, intuitive multiple choice questions. Each question is crafted with detailed explanations to ensure understanding and success.

Multiple Choice

What guideline is violated when an API uses the prefix "set" for non-setter methods?

Explanation:
The guideline that is violated when an API uses the prefix "set" for non-setter methods is G3: Beware of false consistency. This principle emphasizes that consistency in naming should not come at the expense of clarity and understandability. When methods that do not truly set a value are incorrectly prefixed with "set," it creates a misleading expectation about their functionality. Users of the API may anticipate a certain behavior—specifically, that the method alters internal state or a property—when in reality, the method may perform a different action that does not align with what the name suggests. This situation can lead to confusion and misusage of the API, illustrating that maintaining clarity in naming is significantly more important than striving for superficial consistency across method names. In this context, a method's name should accurately reflect its purpose to ensure proper understanding and usability by developers, reinforcing the idea that clarity should take precedence over merely adhering to a uniform naming scheme.

The guideline that is violated when an API uses the prefix "set" for non-setter methods is G3: Beware of false consistency. This principle emphasizes that consistency in naming should not come at the expense of clarity and understandability. When methods that do not truly set a value are incorrectly prefixed with "set," it creates a misleading expectation about their functionality.

Users of the API may anticipate a certain behavior—specifically, that the method alters internal state or a property—when in reality, the method may perform a different action that does not align with what the name suggests. This situation can lead to confusion and misusage of the API, illustrating that maintaining clarity in naming is significantly more important than striving for superficial consistency across method names.

In this context, a method's name should accurately reflect its purpose to ensure proper understanding and usability by developers, reinforcing the idea that clarity should take precedence over merely adhering to a uniform naming scheme.

Subscribe

Get the latest from Examzify

You can unsubscribe at any time. Read our privacy policy