[MS] API naming principle: If there is no direct object, then the direct object is the source object - devamazonaws.blogspot.com
It is a common practice that method names begin with a verb: widget., widget., widget..
Often, the verb is followed by a direct object: widget., widget.. The direct object is the thing that the verb operates on or produces. In the case of SetColor, it is setting the color. In the case of GetAssociatedDoodad it is getting the associated doodad.
Sometimes, the verb is not followed by a direct object at all, such as the widget. method above. In that case, the direct object is the source object: The widget. In the above example, widget. toggles the widget.
<P< All of this may sound obvious, but it's easy to lose sight of this principle.
For example, a team proposed an API with a WidgetNotification and a method widgetNotification.. As written, it sounds like this deletes the widget notification itself, but the intention was for this to delete a notification listener. The methods for creating and deleting listeners should be named something like widgetNotification. and widgetNotification..
As another example, the name of the ApplicationDataManager. method doesn't say what it's creating, so the assumption is that it creates an ApplicationDataManager. But that's not what it creates. It actually creates an ApplicationData object. The method should more properly be named ApplicationDataManager..
An exception to this rule is factory objects. The purpose of factory objects is to create things, so a WidgetFactory. method is assumed to create a widget. But I wouldn't complain if you called your method WidgetFactory., just to be clear about it.
Post Updated on July 24, 2024 at 03:00PM
Thanks for reading
from devamazonaws.blogspot.com
Comments
Post a Comment