-
-
Save lesismal/0e6de663bc22a620c641832e348ecc60 to your computer and use it in GitHub Desktop.
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 | |
type IDevice interface { | |
Fn() | |
Sync() | |
} | |
type DeviceFn interface { | |
Fn() | |
} | |
type PC struct{} | |
func (pc *PC) Fn() { | |
println("PC Device fn!!!") | |
} | |
type Router struct{} | |
func (router *Router) Fn() { | |
println("Router Device sync") | |
} | |
type Device struct { | |
DeviceFn | |
} | |
func (device *Device) Sync() { | |
println("Start Sync ...") | |
device.Fn() | |
println("Start Done.") | |
} | |
func NewDevice(d DeviceFn) IDevice { | |
return &Device{ | |
DeviceFn: d, | |
} | |
} | |
func StartSync(d IDevice) { | |
d.Sync() | |
} | |
func main() { | |
p := NewDevice(&PC{}) | |
r := NewDevice(&Router{}) | |
StartSync(p) | |
StartSync(r) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
output:
Start Sync ... PC Device fn!!! Start Done. Start Sync ... Router Device sync Start Done.