Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

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

Open
MistarQ opened this issue Jun 5, 2022 · 1 comment

Comments

@MistarQ
Copy link

MistarQ commented Jun 5, 2022

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
Copy link
Author

MistarQ commented Jun 5, 2022

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

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant