golang custom interface body (like other language objects)

1  / * 
2  
. 3      structure variables:
 4          defines only a memory structure that describes the layout, only when the structure is instantiated, it will actually allocate memory
 5          is allowed only in the definition of the structure and instantiate field structure.
. 6          type type name {struct
 . 7              Field 1 Field Type 1
 8              Field 2 Field Type 2
 9              ...
 10          }
 11      pointer types of structures: new type keywords (including structures, integer, float, string, etc.) examples of the structural body after an instance will form a structure pointer type
 12 is          var O * type name = new new (type name). 1
 13 is          2 O: = & type name {}
 14          assignment:
 15          . 1 var O * type name = new (type name) {field 1: value}
 16          2 O = XXX field 1.
 . 17         3 p: = & struct {// definition of
 18 is              name String
 . 19          } {// Initialization
 20 is              name: "Lizi",
 21 is          }
 22 is      structured body Method:
 23 is          1. Each method can have only one receiver (minutes: non-pointer type, and pointer type receiver)
 24          second non-pointer type receivers: when the process action, Go language code that runs on the receiver at the time when the non-pointer value is copied to a receiver, the method in the non-pointer of the receiver may obtain received member's value, but ineffective modified
 25          3-pointer type receiver: the receiver type pointer by the pointer to a structure consisting closer to this object-oriented or Self
 26 is          FUNC (receiver variable receiver type) method name (parameter list) (return parameter) {
 27              function body
 28          }
 29          embodiment:
 30          type ObjectType} struct {int ID
 31 is         FUNC (O * ObjectType) SetId (ID) {int
 32              o.id ID =
 33 is              return ID
 34 is          }
 35          O: = new new (ObjectType)
 36          o.SetId (0)
 37 [          Structure embedded features:
 38 is          . 1 embedded structure body member variables can directly access its
 39          second field name is embedded in the structure of its type name
 40          type embedded
 41 is  * / 
42 is Package info_struct

 

Guess you like

Origin www.cnblogs.com/weihexinCode/p/12317058.html