Best Practices - Methods and Operations

The purpose of this document is to provide best practices when developing methods and operations.

Note:

  • Methods are stateful: they already have access to class data (such as properties).
  • Operations are stateless: they do not have access to class data. You have to define the context in which class data operates.

Best practices are as follows:

  1. Follow naming conventions.
  2. Methods and operations for a class or representation should be stored together. This makes it easier to maintain them.
  3. Avoid data duplication. If a class includes child classes, information from either the parent or child classes can be directly accessed without replicating any of it.
  4. Always check for parameters in case any is expected within the method.
  5. Make sure all methods and operations return a status to see if they were successful.
  6. Always check the return value after calling a method or operation. If any error is returned, make sure you deal with the error handling.
  7. Make sure you free any instance created within a method or operation before exiting it.