Quick actions

cmd+k|ctrl+k

Navigation

Languages

OOP GO

Snippet info

Language

Go

Visibility

public

Author

ubaidillah.hf

Created

2022-05-11T03:59:26.911768Z

Updated

2022-05-11T03:59:26.911768Z

package main

import (
    "fmt"
)

type user struct {
  name string
  Age int
}

func (u user) getName() string {
  return u.name
}

func (u user) getUserAge() string {
  return fmt.Sprintf("%s is %d years old", u.getName(), u.Age)
}

// Contoh interface untuk kelas user
type IUserService interface {
  getUserAge() string
}

// Implementasikan interface UserService
func NewUser(name string, age int) IUserService {
  return user{name: name, Age: age}
}

func main() {
  user := NewUser("John Lenon", 29)
  fmt.Println(user.getUserAge())
}
INFO