Python Structs, Receiver Methods & Composition
Go achieves object-oriented design without classes. Group fields into structs, attach value and pointer receiver methods, and leverage struct embedding for elegant composition.
"A struct is like an architectural blueprint. Methods are buttons on the device. Embedding is fitting a standard motor inside a blender instead of rebuilding the motor from scratch."
Deep Dive: How It Works
Struct Definition: Custom compound type aggregating named fields.
Receiver Methods: func (r ReceiverType) Method() attaches behaviors directly to types.
Composition over Inheritance: Struct embedding promotes inner fields and methods to the outer struct.
Syntax Blueprint
type User struct { Name string }
func (u *User) Rename(n string) { u.Name = n }Declare struct fields and bind methods using value or pointer (*T) receivers.
Core Rules to Remember



Common Beginner Traps & How to Fix Them
Using value receiver func (a Account) Deposit(amount) and wondering why balance never changes.Why it happens: A value receiver operates on a local copy of the struct.
How to fix: Change receiver to pointer receiver: func (a *Account) Deposit(amount).
Live Interactive Example
Hit Run Code to see it liveYour Turn: Micro Challenge
No pressure! Edit the starter code below and test your solution with instant feedback.
Rectangle Area & Perimeter Methods
Define a Rectangle struct with Width and Height float64 fields.
Implement an Area() float64 value receiver method.
Implement a Perimeter() float64 value receiver method.
In main(), create a Rectangle with Width 5.0 and Height 3.0, and print "Area: %.1f, Perimeter: %.1f".
Finished reading and practicing?
Mark this lesson as completed to update your course progress.