Design by Contract and Fail Fast

623 views Asked by At

Fail Fast -

Fail-fast is a property of a system or module with respect to its response to failures. A fail-fast system is designed to immediately report at its interface any failure or condition that is likely to lead to failure. Fail-fast systems are usually designed to stop normal operation rather than attempt to continue a possibly flawed process. Such designs often check the system's state at several points in an operation, so any failures can be detected early. A fail-fast module passes the responsibility for handling errors, but not detecting them, to the next-higher system design level.

Design by Contract -

Design by contract (DbC), also known as contract programming, programming by contract and design-by-contract programming, is an approach for designing software. It prescribes that software designers should define formal, precise and verifiable interface specifications for software components, which extend the ordinary definition of abstract data types with preconditions, postconditions and invariants. These specifications are referred to as "contracts", in accordance with a conceptual metaphor with the conditions and obligations of business contracts.

My question is what is the similar and difference in both terms . I thinking that both are for software design.

Fail fast is more of respond to a system failure and Design by Contract is more of the gurantee , the minimum and the expectation of a system.

But how do i actually define the difference between both of them and the similarity.

Thanks for helping .!

2

There are 2 answers

0
Paul Sweatte On

Similarities:

  • Both can be implemented via assertions
  • Both are intrinsic to the design of XML

Differences:

  • Design by Contract doesn't handle unexpected errors
  • Fail fast doesn't handle redundant checks
  • Design by Contract doesn't handle bad requirements
  • Fail fast doesn't handle requirements mapping

References

0
More Than Five On

They are mutually exclusive. A Java iterator is fail fast but also design by contract. Fail fast just means, bomb out in the hope nothing worse will happens (e.g. throw an exception). Whereas something like fail safe, would usually mean when failure happens, make sure nothing worse happens. You can do this by isolating system components or by having something that will handle the case of failure so that nothing bad will happen (e.g. session replication / failover)