class

package
v1.2.89 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 14, 2023 License: MIT Imports: 0 Imported by: 0

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 NewClass

func NewClass() *Class

func (Class) GetDerived

func (task Class) GetDerived() Classer

GetDerived returns actual outermost struct

func (Class) GetDerivedElse

func (task Class) GetDerivedElse(defaultClass Classer) Classer

GetDerivedElse returns actual outermost struct if it is non-{@code nil} and otherwise returns the non-{@code nil} argument.

func (*Class) SetDerived

func (task *Class) SetDerived(derived Classer)

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"
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL