Created
April 3, 2018 16:05
-
-
Save wuriyanto48/e77dd5ef91f13b2bce4037627167cf99 to your computer and use it in GitHub Desktop.
what the heck is this..
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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": "[email protected]"}`}}} | |
//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