3 ms·
Solution: Don't inherit from GameObject. Make GameObject "final" and simply be a container of components. Move all object-specific behaviour into the components
by tomlu 12y ago
Solution: Don't inherit from GameObject. Make GameObject "final" and simply be a container of components. Move all object-specific behaviour into the components.
- snake_case 12y agoBut, I still need inheritance. DuckComponent would need to inherit from Component in order for my GameObject to add that to the list of components attached. Am I wrong?
- yuriks 12y agoThis sounds like the exact case where you'd use a trait.
- snake_case 12y agoYes, I think you're right!
- tomlu 12y agoYou'd use interfaces (or a similar behaviour-indirection mechanism like function pointers). In Rust I suppose you'd use a trait.