Go learning [3] object-oriented

Source: Internet
Author: User

In fact, go objects are far-fetched. In fact, it is interface-oriented. Interface-oriented .. Ha, this is the object-oriented statement. But he is not the object-oriented interface-oriented programming.


The Go interface is similar to an object-oriented generic type. Remember that it is a type. Can be assigned a value. can be assigned a value. But it is also an interface. However, this interface is different from the previously used object-oriented interface. You must define the interface and then implement the interface using the class. The idea of the Go interface is the opposite, which is equivalent to the method of this class. Then we define an interface, which methods are available for this interface. Then this type can be assigned to this interface. That's simple.

Maybe you don't understand.CodeRight:
Type testinterface interface {
Add (a, B INT) int
Multiply (a, B INT) int
}


All types that implement the ADD and multiply methods can be directly assigned to the testinterface type variable.

In addition, the interface can be used as a response when your parameter is water or the type of the returned value is uncertain.



In other go statements, only classes are supported. In upper case, the function can be accessed by an external package. In lower case, this function can be viewed and used only in the package.








Play. After reading this for a long time, nothing can be written. Bytes
next time, start with the development website! OK

Related Article

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.