Method Contracts

// Apr 10, 2015

This post will be somewhat conceptual but equally as important as any of the other ones. It’s 2 weeks into the Lighthouse Labs course right now and one of the instructors David VanDusen has dawned on me an extremely important concept. Method Contracts.

Methods/functions in programming have all have a specific purpose, and their method contracts define their functionality. When writing any method, you should be able to clearly state it’s method contract in one sentence WITHOUT using the word and.


The blueprint for a method contract is as follows:

  1. What arguments are the method parameters taking, and what are the argument types?
  2. What functionality is the method responsible for?
  3. What are the values the method returns and their value types?
  4. What exceptions do the method raise under what circumstances?


A method is definitive and well designed when you can answer those 4 questions without a shadow of a doubt.

Invaluable expertise; I’ll never look at methods the same again.