Skip to content

Instantly share code, notes, and snippets.

@tobiassjosten
Created June 21, 2012 13:48
Show Gist options
  • Save tobiassjosten/2965814 to your computer and use it in GitHub Desktop.
Save tobiassjosten/2965814 to your computer and use it in GitHub Desktop.
function addition(NumbersInterface $numbers) {
// We know for sure that we can access $numbers->number1, $numbers->number2
// and $numbers->number2. This function can now do its one thing without
// being burdened with validation.
// http://en.wikipedia.org/wiki/Single_responsibility_principle
// http://en.wikipedia.org/wiki/Design_by_contract
}
interface NumbersInterface {
public $number1;
public $number2;
public $number3;
}
class Number implements fooInterface {
public $number1 = 1;
public $number2 = 2;
public $number3 = 3;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment