mirror of
https://github.com/crazybber/go-pattern-examples.git
synced 2024-11-29 23:16:03 +03:00
60 lines
905 B
Go
60 lines
905 B
Go
|
package facade
|
||
|
|
||
|
import "fmt"
|
||
|
|
||
|
func NewAPI() API {
|
||
|
return &apiImpl{
|
||
|
a: NewAModuleAPI(),
|
||
|
b: NewBModuleAPI(),
|
||
|
}
|
||
|
}
|
||
|
|
||
|
//API is facade interface of facade package
|
||
|
type API interface {
|
||
|
Test() string
|
||
|
}
|
||
|
|
||
|
//facade implement
|
||
|
type apiImpl struct {
|
||
|
a AModuleAPI
|
||
|
b BModuleAPI
|
||
|
}
|
||
|
|
||
|
func (a *apiImpl) Test() string {
|
||
|
aRet := a.a.TestA()
|
||
|
bRet := a.b.TestB()
|
||
|
return fmt.Sprintf("%s\n%s", aRet, bRet)
|
||
|
}
|
||
|
|
||
|
//NewAModuleAPI return new AModuleAPI
|
||
|
func NewAModuleAPI() AModuleAPI {
|
||
|
return &aModuleImpl{}
|
||
|
}
|
||
|
|
||
|
//AModuleAPI ...
|
||
|
type AModuleAPI interface {
|
||
|
TestA() string
|
||
|
}
|
||
|
|
||
|
type aModuleImpl struct{}
|
||
|
|
||
|
func (*aModuleImpl) TestA() string {
|
||
|
return "A module running"
|
||
|
}
|
||
|
|
||
|
//NewBModuleAPI return new BModuleAPI
|
||
|
func NewBModuleAPI() BModuleAPI {
|
||
|
return &bModuleImpl{}
|
||
|
}
|
||
|
|
||
|
//BModuleAPI ...
|
||
|
type BModuleAPI interface {
|
||
|
TestB() string
|
||
|
}
|
||
|
|
||
|
type bModuleImpl struct{}
|
||
|
|
||
|
func (*bModuleImpl) TestB() string {
|
||
|
return "B module running"
|
||
|
}
|