Caught off guard: Should you declare more than one “class” within a single file (for Go)?

Original image — source: pixabay, author: LukasBasel

“Why do we declare more than one “class” in a single .go file?”

Methods with a “Page” and “*Page” as receivers in Go, vs a similar class implementation in Ruby

Examining other languages


Modified Image — source: Oracle
Modified Image — source: Oracle


Modified image — source: Ruby on Rails guides


Go and its conventions here?

Composition through type embedding in Go. On the left-half, it may seem like it behaves like inheritance, but on the right-half, you can clearly see that Go support multiple embedded types and that we shouldn’t treat it like inheritance.

Go packages

Original image: source — Go code organization
Each of the green rectangles above is considered as a single package.
Original image: source — Go SQL package — sql.go

So what gives?

Staff Engineer, Hubble | Former Tech Lead, Rakuten Viki |

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store