This repository has been archived on 2021-09-07. You can view files and clone it, but cannot push or open issues or pull requests.

35 lines
487 B
Go
Raw Permalink Normal View History

2018-01-02 17:19:50 +03:00
package strategy
import (
"fmt"
)
// Abstraction
type LoggerStrategy interface {
Write(string) error
}
// Strategy 1
type FileLogger struct {}
func (l FileLogger) Write(data string) error {
fmt.Println("Writed to file...")
return nil
}
// Strategy 2
type DbLogger struct {}
func (l DbLogger) Write(data string) error {
fmt.Println("Writed to db..")
}
// Consumer
type Logger struct{
logger LoggerStrategy
}
func (l *Logger) Log(data string) error {
l.logger.Write(data)
}