Tuesday, November 22, 2005

Programming Objects

Programming Objects

  1. Early bind objects whenever possible.
  2. Use .Net objects rather than API calls whenever possible.
  3. Expose public properties, not public variables.
  4. Always close what you open
    m_dstContacts.Close()
    m_cnADOConnection.Close()
  5. Use Overloads to create a property or method with the same name as another property or method but with a different argument list.
  6. Create Dispose methods for all your objects.
    Place cleanup code in that method
    Call the Dispose on each and every object that has one, once you are finished with the object.
    Note: When creating shared components, you must be careful about the code you place in a custom Dispose method. Releasing the resource could cause problems for the remaining clients that are sharing the object.
  7. Create constructors for a class whenever possible
    Note: You cannot use the keyword Overloads on constructors, even though creating multiple constructors is indeed creating overloaded methods.
  8. Add a finalizer to a class only when necessary.
    Caution: You should avoid referencing other objects in your finalize code because the nature of garbage collection is such that the finalizers aren’t executed in any special order.
  9. Use With..End With to increase performance and make code more readable.

No comments: