Skip to content

Commit

Permalink
Interface struct
Browse files Browse the repository at this point in the history
  • Loading branch information
jaringankantor committed Oct 15, 2021
1 parent bca62d7 commit 12d5750
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 2 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ module github.com/jaringankantor/Pertemuan03LatihanMain

go 1.17

require github.com/jaringankantor/Pertemuan03LatihanModule v1.0.6 // indirect
require github.com/jaringankantor/Pertemuan03LatihanModule v1.1.1 // indirect
10 changes: 10 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,13 @@ github.com/jaringankantor/Pertemuan03LatihanModule v1.0.5 h1:zfbBqW7n1xXJ7/zjVad
github.com/jaringankantor/Pertemuan03LatihanModule v1.0.5/go.mod h1:ar5+g5PbzIWAdHG4VNFF4Vwgnz9OeuAsULrpY3RYzaw=
github.com/jaringankantor/Pertemuan03LatihanModule v1.0.6 h1:f7olEGEGY9tYz3Gyb3z2U/JroLq/9eUIBtdey9+MEj4=
github.com/jaringankantor/Pertemuan03LatihanModule v1.0.6/go.mod h1:ar5+g5PbzIWAdHG4VNFF4Vwgnz9OeuAsULrpY3RYzaw=
github.com/jaringankantor/Pertemuan03LatihanModule v1.0.7 h1:WQ4xyAzfDo12fTGDozX43mVdjlLqh2Nf+GvB4AfOodU=
github.com/jaringankantor/Pertemuan03LatihanModule v1.0.7/go.mod h1:ar5+g5PbzIWAdHG4VNFF4Vwgnz9OeuAsULrpY3RYzaw=
github.com/jaringankantor/Pertemuan03LatihanModule v1.0.8 h1:m14o4gNnWVY+DbV9BWDsOD46qGXfF9LldIDhRdPjSbE=
github.com/jaringankantor/Pertemuan03LatihanModule v1.0.8/go.mod h1:ar5+g5PbzIWAdHG4VNFF4Vwgnz9OeuAsULrpY3RYzaw=
github.com/jaringankantor/Pertemuan03LatihanModule v1.0.9 h1:QzgmVqBDjzueGghs1jeqNJG8S/EWxYKH+sN53RXiDBQ=
github.com/jaringankantor/Pertemuan03LatihanModule v1.0.9/go.mod h1:ar5+g5PbzIWAdHG4VNFF4Vwgnz9OeuAsULrpY3RYzaw=
github.com/jaringankantor/Pertemuan03LatihanModule v1.1.0 h1:qPH2ciR9zPGdnM4ldX1QKalq/M607HQ4G9Q//MsiyF4=
github.com/jaringankantor/Pertemuan03LatihanModule v1.1.0/go.mod h1:ar5+g5PbzIWAdHG4VNFF4Vwgnz9OeuAsULrpY3RYzaw=
github.com/jaringankantor/Pertemuan03LatihanModule v1.1.1 h1:X/ajbtb9rPfMfFA2uyrkuBpq9bOiCR3KoknzUGgKuRU=
github.com/jaringankantor/Pertemuan03LatihanModule v1.1.1/go.mod h1:ar5+g5PbzIWAdHG4VNFF4Vwgnz9OeuAsULrpY3RYzaw=
38 changes: 37 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,25 @@ import (
modulasi "github.com/jaringankantor/Pertemuan03LatihanModule"
)

//interface struct

type PersegiInterface interface {
Keliling() int
Luas() int
}

type InputPersegi struct {
a, b int
}

func (in InputPersegi) Keliling() int {
return (in.a + in.b) * 2
}

func (in InputPersegi) Luas() int {
return in.a * in.b
}

func main() {
a := 3
b := 5
Expand Down Expand Up @@ -35,5 +54,22 @@ func main() {
modulasi.User(name, isAktif)

//struct
modulasi.TampilData
modulasi.TampilData()

//struct module
welcome := modulasi.Pegawai{Nama: "Anwar"}
welcome.SelamatDatang("Budi")

//Anonymous struct
modulasi.AnonymousDataOrtu()

//interface struct

persegi := InputPersegi{
a: 23,
b: 45,
}

fmt.Println("Jika a=", persegi.a, ", b=", persegi.b, ". Maka keliling=", persegi.Keliling())
fmt.Println("Jika a=", persegi.a, ", b=", persegi.b, ". Maka luas=", persegi.Luas())
}

0 comments on commit 12d5750

Please sign in to comment.