In Go, it is conventional to name interfaces with a single method by appending the method name with the suffix "-er" or a similar modification. This results in an agent noun, as seen in interfaces like Reader, Writer, Formatter, and CloseNotifier.
For interfaces that define multiple methods, it is recommended to choose a name that accurately describes their purpose, such as net.Conn, http.ResponseWriter, or io.ReadWriter.
Avoid using generic names like this or self for receiver types. It is better to use a concise abbreviation that reflects the receiver type, typically one or two characters. For example, c or cl for Client, and r for Rectangle. This approach ensures consistency across the type's methods and emphasizes the receiver's role as an obvious argument.
In the provided code, it would be appropriate to consider the following interface names:
For the ServerSession interface, ServerSession or Session would be suitable names.
The above is the detailed content of How Should Interfaces Be Named in Go?. For more information, please follow other related articles on the PHP Chinese website!