package main import "fmt" func NewAPI() API { return &apiImpl{ a: NewAModuleAPI(), b: NewBModuleAPI(), } } // API is facade interface of facade package type API interface { Test() string } // apiImpl facade implement type apiImpl struct { a AModuleAPI // submodule 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" }