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.
2018-01-08 21:15:03 +04:00

37 lines
668 B
Go

package bridge
import "fmt"
import "errors"
// Bridge interface
type Drawer interface {
DrawRectangle(w, h int)
}
type GreenRectangleDrawer struct {}
func (d GreenRectangleDrawer) DrawRectangle(w, h int) {
fmt.Printf("Green rectangle W: %d, H: %d", w, h)
}
type RedRectangleDrawer struct {}
func (d RedRectangleDrawer) DrawRectangle(w, h int) {
fmt.Printf("Red rectangle W: %d, H: %d", w, h)
}
type Shape interface {
Draw() error
}
type Rectangle struct {
Width, Height int
drawer Drawer
}
func (d Rectangle) Draw () error {
if d.drawer == nil {
return errors.New("Drawer not initialized.")
}
d.drawer.DrawRectangle(d.Width, d.Height)
return nil
}