Enforcing Order on Component Methods

"To be a good component, an object should not depend on its client calling its methods in any particular order." [David Platt, MS Systems Journal Aug 97, "The Free Threading Model"]

If you require your methods to be called in some particular order, e.g. Init() before DoIt(), then at least do the following:

  1. Document this requirement everywhere you can, e.g. in the interface file(s) that are distributed to use your component, in the source code of the component.
  2. Check/Enforce the calling order within your component, e.g. define an enum type that represents the various states your component can be in and then make sure it is in the proper state when your methods are called.

Never assume the client will make the calls in the correct order. Assume just the opposite.