Created
December 14, 2014 13:28
-
-
Save iporsut/aab570907a2d71bfbc28 to your computer and use it in GitHub Desktop.
Spike Logger Go
This file contains hidden or 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 Logger interface { | |
log(message string) | |
} | |
type DefaultLogger struct { | |
} | |
func (dl *DefaultLogger) log(message string) { | |
fmt.Println(message) | |
} | |
type IA interface { | |
A() | |
} | |
type IALogger struct { | |
IA | |
Logger | |
} | |
func (l *IALogger) A() { | |
l.Logger.log("Begin A") | |
l.IA.A() | |
l.Logger.log("End A") | |
} | |
type IB interface { | |
B() | |
} | |
type IBLogger struct { | |
IB | |
Logger | |
} | |
func (l *IBLogger) B() { | |
l.Logger.log("Begin B") | |
l.IB.B() | |
l.Logger.log("End B") | |
} | |
type IC interface { | |
C() | |
} | |
type ICLogger struct { | |
IC | |
Logger | |
} | |
func (l *ICLogger) C() { | |
l.Logger.log("Begin C") | |
l.IC.C() | |
l.Logger.log("End C") | |
} | |
type ABCImp struct { | |
} | |
func (a *ABCImp) A() { | |
fmt.Println("Method A") | |
} | |
func (b *ABCImp) B() { | |
fmt.Println("Method B") | |
} | |
func (c *ABCImp) C() { | |
fmt.Println("Method C") | |
} | |
func main() { | |
var ia IA | |
var ib IB | |
var ic IC | |
abc := &ABCImp{} | |
ia = &IALogger{abc, &DefaultLogger{}} | |
ia.A() | |
ib = &IBLogger{abc, &DefaultLogger{}} | |
ib.B() | |
ic = &ICLogger{abc, &DefaultLogger{}} | |
ic.C() | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment