DEV Community

Discussion on: Is Go an Object Oriented language?

Collapse
 
theodesp profile image
Theofanis Despoudis • Edited

You forgot to mention that methods also can be applied to any type and not only Structs. For example this is valid:

package main

import (
    "fmt"
)

type Integer int


func (d Integer)Squared() Integer {
    return d * d
}

func main() {
    fmt.Println("Hello, playground")
    var d Integer = Integer(10).Squared()
    fmt.Println(d)
}

Collapse
 
web3coach profile image
Lukas Lukac

That is a great feature indeed you are right but not really forgot. I also didn't mention type functions, Interfaces etc. Maybe in another post :) The main goal is to show the the difference between a classical Struct and a classical Class. Assigning methods to primitive types is a bonus that normal OO languages don't have so not really necessary to compare as there isn't any comparison.