ELI5: Explain Like I'm 5

Design by contract

Design by contract (DBC) is a way of making sure that the parts of a program or system fit together correctly. It's like having a contract (or agreement) between different parts of the program, to make sure that everybody does what they're supposed to do.

DBC starts by making sure that all the parts of the program understand what their job is. For example, if you want a program to sort numbers, you would need to make sure that it knows how to sort a list of numbers. This is where the "contract" comes in: the program should be given a list of numbers and know exactly how to put them in order.

The program is also given a set of rules, called "assertions" or "preconditions". These rules tell the program what it is allowed to do, and what it should not do. If the program breaks any of these rules--for example, tries to sort numbers that it was not given--then it will not do its job correctly.

Finally, the program also needs a set of results, or "postconditions", to determine if the program did its job correctly. In the sorting example, the postcondition might say that if the program receives a list of numbers, it should return a list of those numbers in ascending order. If the list that the program returns does not match this postcondition, then the program did not do its job correctly.

In summary, DBC is a way of making sure that the parts of a program or system fit together correctly. It sets up rules and expectations for the program, so that it can do its job correctly and predictably.