Class ⇄ struct + methodClass ⇄ struct + methods
Go không có class. Dữ liệu nằm trong struct, hành vi là method gắn với struct qua receiver.Go has no classes. Data lives in a struct; behaviour is methods attached through a receiver.
public class Order {
private final String id;
private long total;
public Order(String id) { this.id = id; }
public void add(long amount) { total += amount; }
}type Order struct {
id string
total int64
}
func NewOrder(id string) *Order { return &Order{id: id} }
func (o *Order) Add(amount int64) { o.total += amount }