ਡਿਜ਼ਾਈਨ ਬਾਈ ਕਨਟ੍ਰੈਕਟ (DbC) ਇੱਕ ਮੇਥਡ ਅਤੇ ਇਸਦੇ ਕੋਲਰ ਵਿਚਕਾਰ ਸਬੰਧ ਨੂੰ ਇੱਕ ਰਸਮੀ ਸਮਝੌਤੇ ਵਜੋਂ ਮੰਨਦਾ ਹੈ, ਜਿਸ ਨੂੰ ਤਿੰਨ ਚੀਜ਼ਾਂ ਦੁਆਰਾ ਪਰਿਭਾਸ਼ਿਤ ਕੀਤਾ ਗਿਆ ਹੈ: preconditions (ਕੋਲਰ ਨੂੰ ਕੀ ਗ੍ਰੈਂਟੀ ਦੇਨੀ ਚਾਹੀਦੀ ਹੈ), postconditions (ਮੇਥਡ ਬਦਲੇ ਵਿੱਚ ਕੀ ਗ੍ਰੈਂਟੀ ਦਿੰਦਾ ਹੈ), ਅਤੇ invariants (ਆਬਜੈਕਟ ਲਈ ਹਮੇਸ਼ਾ ਕੀ ਸੱਚ ਰਹਿੰਦਾ ਹੈ)।
ਤਿੰਨ ਜ਼ਿੰਮੇਵਾਰੀਆਂ
PRECONDITION → caller's duty: inputs/state the method requires to run correctly
POSTCONDITION → method's duty: what it promises on return (if precondition held)
INVARIANT → always-true property of the object, before and after every method
