Objective
1. Specification for access modifiers
The go language requires public-modified variables to start with a capital letter
Variables with private modifier start with lowercase letters
This allows you to directly exempt the public and private keywords
2, curly braces position specification
If expression{if expression
...... { ......
} }
This is the correct wording, and this is the wrong writing.
3, go language error handling mechanism advantages, there are error types
4, when using the go language to imitate inheritance, if the structure of the parent class A and the structure of the child Class B has the same name of the attribute V, when B calls A's method output v value, the printout will be the parent class Property value
For example, the following code:
Package Main
Import "FMT"
Type Dog struct {
Name string
}
Type Bdog struct {
Dog
Name string
}
Func (this *dog) Callmyname () {
Fmt. Printf ("My name is%q\n", This.getname ())
}
Func (this *dog) GetName () string {
Return this.name
}
Func Main () {
B: = new (Bdog)
B.name = "This is a Bdog name"
B.dog.name = "This is a Dog name"
B.callmyname ()
}
5, Go Language interface and type can be converted to each other, but the type to implement all the methods of the interface
Type Bird struct {
...
}
Func (b *bird) Fly () {
Fly in a bird's way
}
Type IFly Interface {
Fly ()
}
Func Main () {
var Fly IFly = new (Bird)
Fly. Fly ()
}
If you want to modify the methods in the interface later, you can redefine an interface to use, which can reduce the code modification and reduce the coupling
Go language Learning notes before words section