2.15. Go language function method

发布时间 :2023-10-12 23:00:08 UTC      

There are both functions and methods in Go language. One method is a function that contains the recipient, which can be a value or a pointer to a named type or struct type. All methods of a given type belong to the method set of that type. The syntax format is as follows:

func (variable_name variable_data_type) function_name() [return_type]{
   /* Function body*/
}

The following defines a structure type and a method for that type:

2.15.1. Example #

package main
import (
   "fmt"
)
/* Define Structure */
type Circle struct {
  radius float64
}
func main() {
  var c1 Circle
  c1.radius = 10.00
  fmt.Println("Area of a circle = ", c1.getArea())
}
//This method belongs to a method in a Circle type object
func (c Circle) getArea() float64 {
  //c.radius is an attribute in an object of type Circle
  return 3.14 * c.radius * c.radius
}

The result of the above code execution is:

Area of a circle =  314

Principles, Technologies, and Methods of Geographic Information Systems  102

In recent years, Geographic Information Systems (GIS) have undergone rapid development in both theoretical and practical dimensions. GIS has been widely applied for modeling and decision-making support across various fields such as urban management, regional planning, and environmental remediation, establishing geographic information as a vital component of the information era. The introduction of the “Digital Earth” concept has further accelerated the advancement of GIS, which serves as its technical foundation. Concurrently, scholars have been dedicated to theoretical research in areas like spatial cognition, spatial data uncertainty, and the formalization of spatial relationships. This reflects the dual nature of GIS as both an applied technology and an academic discipline, with the two aspects forming a mutually reinforcing cycle of progress.