Skip to content

Instantly share code, notes, and snippets.

@Jeffwan
Created April 14, 2020 23:17
Show Gist options
  • Save Jeffwan/01badb1a1ad37bf20f0e3406002dd813 to your computer and use it in GitHub Desktop.
Save Jeffwan/01badb1a1ad37bf20f0e3406002dd813 to your computer and use it in GitHub Desktop.
package mxnet
import "fmt"
type ControllerInterface interface {
// Returns the Controller name
Method1() string
// Returns the GroupVersionKind of the API
Method2() string
}
// JobController abstracts other operators to manage the lifecycle of Jobs.
type AbstractJobController struct {
Controller ControllerInterface
}
func (ajc *AbstractJobController) Start() {
// "main logic, need to call controllerInterface"
fmt.Println("result: " + ajc.Controller.Method1() + "," + ajc.Controller.Method2())
}
func (ajc *AbstractJobController) Method1() string {
return "method 1 from abstract controller"
}
// my requirement is in AbstractJobController. it can implements Method1.
/********************************************************************************/
type ConcreteController struct {
AbstractJobController
}
// this is concrete controller path
func NewConcreteController() *ConcreteController{
cc := &ConcreteController{}
jc := AbstractJobController{
Controller: cc,
}
cc.AbstractJobController = jc
return cc
}
func (cc *ConcreteController) Method1() string {
return "method 1 from concreate controller"
}
func (cc *ConcreteController) Method2() string {
return "method 2 from concreate controller"
}
func main() {
c := NewConcreteController()
c.Start()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment