sandeepk

DBC

Design by Contract is the software designing process that takes a contract based approach in developing the software that does no more and no less than it claims to do.

What is Contract? A contract is a document that defines the rights and responsibilities of both the party involved in the agreement and which list the repercussions if either party fails to abide by the contract. We all have seen or been in contact with your Landlord or the employment contract that specifies the roles and responsibilities that you must fulfill.

A Similar process we follow while developing the software, where we focus on documenting (and agreeing to) the rights and responsibilities of software modules to ensure program correctness. While writing the contract these questions will be helpful to get things clear.

  • What does the contract expect?
  • What does the contract guarantee?
  • What does the contract maintain?

The software which follows the Design by Contract has these condition specified

  • Preconditions, are the condition which must be true before calling the routine, if violated routine should never be called.
  • Postconditions, after the routines are finished the state which needs to be achieved should be achieved.
  • Class Invariant, A class ensures that this condition is always true from the perspective of a caller. During internal processing of a routine.

Why Design by Contract can be a good approach ?

  • DBC doesn’t require any setup or mocking
  • DBC we can define both the success and failure cases.
  • DBC can be used during the design phase, development, and deployment phase.
  • DBC fits in nicely with our concept of crashing early.

Conclusion Most of you are thinking, do we need another development approach as we already have Test-driven development (TDD). DBC and TDD are different approaches to the broader topic of the software development process. They both have value and both have used in different situations. DBC approach can be used across the Design, Development, and Deployment. DBC fits perfectly in the world where we follow the concept of crashing early. So give it a shot, will be happy to discuss it, you can reach me out her

Cheers!

#100DaysToOffload #SoftwareDevelopment #DBC #DesignByContract