traditional OOP thru “Embedded Interface” and Go’s preferred composition

Golang is not a traditional object oriented programming language. Instead, it distills a few OO programming primitives and allow you to compose them to achieve different OO designs.

1. Methods (or method-set): for “abstract data types”

In traditional OOP, methods are inherently bound with class and objects. In Go, methods can be defined for any “named”/”defined” types. Instead of everything is an object as in some OO language, everything (almost) can be attached methods.

So we can have methods defined for integers:

type MyInt int
func (mi MyInt) addMore(more MyInt) MyInt {
return mi+more

Please note there is no “wrapping” objects needed for primitive types as in…

ygl code

build it, break it.

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