Methods
A method is a function with a receiver.
The receiver is the type the method belongs to, often a struct.
Think of it as giving your form special buttons it can press.
Methods let you attach actions to your data without a class tree.
Value receivers
With a value receiver, the method gets a copy.
That is good for reading fields.
It is also good for returning new values without changing the original.
Pointer receivers
Use a pointer receiver when the method should update the value: func (r *Rect) Scale(...).
Also use it when copying a big struct would be slow.
The method gets the house address, not a copy of the whole house.
Calling methods
Use a dot: value.Method().
Go can take an address for you when needed.
So c.Inc() still works even if Inc wants a pointer.
Methods on non-struct types
You can define methods on any named type in the same package.
Even aliases of built-ins work.
The type just cannot come from another package.
Stay consistent
If any method needs a pointer receiver, use pointer receivers for that type's methods.
Mixed styles confuse readers.
If one method needs a pointer receiver, prefer pointer receivers for that type.
Test yourself
Three quick questions made just for this lesson. Earn 10 XP per correct answer.