Documentation
¶
Overview ¶
Design-by-Contract for Go
Design by Contract is a programming methodology which binds the caller and the function called to a contract. The contract is represented using Hoare Triple:
{P} C {Q}
where {P} is the precondition before executing command C, and {Q} is the postcondition.
See Also ¶
* http://en.wikipedia.org/wiki/Design_by_contract * http://en.wikipedia.org/wiki/Hoare_logic * http://dlang.org/dbc.html
Index ¶
- func Check(b bool, message ...interface{})
- func Ensure(b bool, message ...interface{})
- func Invariant(obj InvariantTester, message ...interface{})
- func InvariantSimple(obj InvariantSimpleTester, message ...interface{})
- func Require(b bool, message ...interface{})
- type InvariantSimpleTester
- type InvariantTester
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Ensure ¶
func Ensure(b bool, message ...interface{})
Ensure checks the postconditions are satisfied before returning to the caller.
Example Code
type Data struct { a int } func (*d Data) Set(a int) { d.a = a godbc.Ensure(d.a == a) }
func Invariant ¶
func Invariant(obj InvariantTester, message ...interface{})
Invariant calls the objects Invariant() receiver to test the object for correctness.
The caller object must provide an object that supports the interface InvariantTester
To see an example, please take a look at the godbc_test.go
func InvariantSimple ¶
func InvariantSimple(obj InvariantSimpleTester, message ...interface{})
InvariantSimple calls the objects Invariant() receiver to test the object for correctness.
The caller object must provide an object that supports the interface InvariantSimpleTester and does not need to provide a String() receiver
Types ¶
type InvariantSimpleTester ¶
type InvariantSimpleTester interface {
Invariant() bool
}
InvariantSimpleTester is an interface which provides a receiver to test the object
type InvariantTester ¶
type InvariantTester interface { InvariantSimpleTester String() string }
InvariantTester is an interface which provides not only an Invariant(), but also a receiver to print the structure