Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Class ¶
type Class struct {
// contains filtered or unexported fields
}
func (Class) GetDerived ¶
GetDerived returns actual outermost struct
func (Class) GetDerivedElse ¶
GetDerivedElse returns actual outermost struct if it is non-{@code nil} and otherwise returns the non-{@code nil} argument.
func (*Class) SetDerived ¶
SetDerived updates actual outermost struct
type Classer ¶
type Classer interface { GetDerived() Classer GetDerivedElse(defaultClass Classer) Classer SetDerived(derived Classer) }
Classer is an interface to enhance go's embed struct with virtual member function in C++|Java It's used like this: import "github.com/searKing/golang/go/util/class"
type Pet struct { class.Class }
func (pet *Pet) Name() string { return "pet" }
func (pet *Pet) VirtualUpperName() string { p := pet.GetDerivedElse(pet).(Peter) return strings.ToUpper(p.Name()) }
func (pet *Pet) UpperName() string { return strings.ToUpper(pet.Name()) }
//Dog derived from Pet
type Dog struct { Pet }
func NewDogEmbedded() *Dog { return &Dog{} }
func NewDogDerived() *Dog { dog := &Dog{} dog.SetDerived(dog) return dog }
func (dog *Dog) Name() string { return "dog" }
Click to show internal directories.
Click to hide internal directories.