Contract design (DbC) Impressions

Source: Internet
Author: User
Tags assert

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.