xiaonanln / goworld

Scalable Distributed Game Server Engine with Hot Swapping in Golang
Apache License 2.0
2.53k stars 450 forks source link

is it reasonable for goword.GetSpace returing *space object instead of Ispace? #113

Open MistarQ opened 2 years ago

MistarQ commented 2 years ago

here is the seene

type MySpace struct { goworld.Space // Space type should always inherit from entity.Space }

i create a space called mySpace, if i use func GetSpace(id common.EntityID) *Space i will get an Space and i can not change it into mySpace unless use `mySpace := (MySpace)(unsafe.Pointer(space))`

and if i change GetSpace into func GetSpace(id EntityID) entity.ISpace { return entity.GetSpaceI(id) }

then we can easily cast ISpace into mySpace

ms := goworld.GetSpaceI(monster.Space.ID).(*MySpace)``

MistarQ commented 2 years ago

其实就是想问多态的情况下是否应该返回接口Ispace而非父类对象*Space