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:
- Follow naming conventions.
- Methods and operations for a class or representation should be stored together. This makes it easier to maintain them.
- 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.
- Always check for parameters in case any is expected within the method.
- Make sure all methods and operations return a status to see if they were successful.
- Always check the return value after calling a method or operation. If any error is returned, make sure you deal with the error handling.
- Make sure you free any instance created within a method or operation before exiting it.