Contractual design can be understood as a practice of regular programming:
If you use my three-legged cat ability to formalize this practice, it is generally as follows (if there is an incorrect position, please correct me):
1, for the method of precondition & postcondition:
Function (Regularmthod) =
^ regularfunction
^ General-class-method
^ Assert(precondition)
^ Assert(postcondition);
= F1 (F2) {F1, F2:regularmethod}
|-> assert (f2.precondition) = assert (F1.postcondition)
When all methods satisfy the above conditions, it means that the input of the program satisfies the assert (precondition), then its output also satisfies the Assert (postcondition), which logically guarantees the correctness of the program. This is for method calls or function calls, which can be implemented in a language that has functions or procedures. I personally understand the regularization of the operation combination (regularity).
2. The invariant type of class invariant:
Class (Invariantclass) =
^ General-class
^ Invariant:assert (invariant) when any method called.
All directly living indirect subclasses of a class have to satisfy its invariant invariant, so that the class and its derived classes are guaranteed to be correct on the data, and the personal understanding is the regularization of the information combination.
Combined with the above two points, the operation and the data combination are implemented in the regularization, that is, the object-oriented regularization, so that in theory the regularization of the object and the object constructed by the program is correct.
3, the appropriate DBC
Overkill If we carry out the DBC in detail for each class, it is a time-consuming, painful and unnecessary thing to do, just as you are good at preventing thieves, but it is not appropriate to keep everyone except yourself as a thief. We should be appropriate to DBC.
DBC is also a thought, a mode of thinking, for how to construct high-quality software to point out a path, it tells us, according to the law, to reach the other side of high quality. If applied in practice, it should be based on specific circumstances.
Contract design (DbC) Impressions