Documenting Methods

Finally, let’s talk about methods. In your documentation hierarchy, a specific class contains its methods, with each method listed as a sibling to the other methods under that class. This structured organization helps illustrate the relationship between the class and its methods, making it easier for users to understand how to interact with the functionality of the class.

Let’s define what a method is first:

A “method” is a function that’s associated with an object or class. They define the behavior of objects by operating on their data (attributes or properties). Methods allow objects to perform actions, access or modify their internal state, and interact with other objects. They’re the tools in the toolbox.

“Method signature” refers to the unique identity of a method you document. It is typically defined by the method’s name, the number and types of its parameters (inputs), and sometimes its return type. The signature serves as the “blueprint” for how the method should be called and what it expects as input.

The method signature includes:

ComponentDescription
Method NameThe name used to call or invoke the method. It should be descriptive of the action the method performs, such as accelerate, getBalance, or calculateTax.
ParametersInputs to the method, defined within parentheses after the method name (e.g., speedIncrease in accelerate(speedIncrease)). Parameters allow the method to use data in its execution.
Return Type (optional)Specifies the type of data the method returns once it finishes executing (e.g., int, double, String). If the method does not return anything, the return type is void.
Access Modifiers (optional)Define the visibility and accessibility of the method. Common modifiers include public, private, and protected, determining whether the method can be accessed inside or outside the class.
Exceptions (optional)List of errors (exceptions) that the method might throw or handle during execution. For example, IOException indicates that an input/output error might occur. This helps users handle errors properly.

accelerate(speedIncrease): number

  • Method name: accelerate
  • Input parameter: speedIncrease of type number
  • Return type: number
  • Class context: The method belongs to the Car class.

Documenting method signatures involves clearly describing each method within the context of its class. After documenting these building blocks, your content structure might look something like this:

This hierarchy mirrors the structure found in library repositories. In open-source or externally facing repositories, documentation helps users navigate and understand the library. In internal or private repositories, documenting hierarchies and dependencies is crucial for enabling development through the available tools, ensuring developers can efficiently build and maintain the system by understanding how components interact and depend on each other.

2 thoughts on “Documenting Methods

Leave a comment