39. Toad Notes Go language--interface

Source: Internet
Author: User
This is a creation in Article, where the information may have evolved or changed.

39. Toad Notes Go language--interface

In go, the reserved word interface is given a number of different meanings. Each type has an interface, which means that a collection of methods is defined for that type.

An interface is defined as a collection of methods. Method contains the actual code. In other words, an interface is defined, and the method is implemented. Therefore, the receiver cannot be defined as an interface type, and doing so will cause invalid receiver type ... Compiler error.

According to the rules, the single-method interface is named method name plus-er suffix: reader,writer,formatter, etc.

There are a bunch of such names that efficiently reflect their responsibilities and the names of the functions they contain. Read,write,close,flush,string and so on have a normative statement and meaning. To avoid confusion, do not let the same name be used unless there is a similar declaration and meaning. Conversely, if a type implements the same method as a well-known type, the same name and declaration are used, and the string conversion method is named string instead of ToString.

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.