Skip to content

Instantly share code, notes, and snippets.

@wuriyanto48
Created April 3, 2018 16:05
Show Gist options
  • Save wuriyanto48/2eeb7ea82c623cf4509a8322a033e95c to your computer and use it in GitHub Desktop.
Save wuriyanto48/2eeb7ea82c623cf4509a8322a033e95c to your computer and use it in GitHub Desktop.
what the heck is this..
package main
import (
"fmt"
)
type OnClickListener interface {
OnClick()
}
type Component struct{
listener OnClickListener
}
func(c Component) SetOnClickListener(l OnClickListener){
c.listener = l
}
func(c Component) Invoke(){
c.listener.OnClick()
}
type Button struct{
Component
}
type RadioButton struct{
Component
}
type ButtonSendEmailListener struct{
Data string
}
func(m ButtonSendEmailListener) OnClick(){
fmt.Printf("Send Email %s", m.Data)
}
type ButtonRequestTwitterApi struct{
Data string
}
func(m ButtonRequestTwitterApi) OnClick(){
fmt.Printf("Send HTTP request twitter %s", m.Data)
}
type MockButton struct{
Data string
}
func(m MockButton) OnClick(){
fmt.Printf("Mock Button for Unit Testing %s", m.Data)
}
func EventButton(b Button){
b.Invoke()
}
func main() {
//btn1 := Button{Component{ButtonSendEmailListener{"Email To Pak Lod"}}}
//btn1.Invoke()
//btn2 := Button{Component{ButtonRequestTwitterApi{`{"username": "wuriyanto", "email": "wuriyanto@gmail.com"}`}}}
//EventButton(btn2)
mockBtn := Button{Component{MockButton{`{"some value from mock"}`}}}
EventButton(mockBtn)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment