Add more control for overriding functions in GDScript #4009
shelerr
started this conversation in
Engine Core
Replies: 1 comment
-
hi @shelerr, instead of |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I often find myself writing code with a single base class (for example, an "enemy") and many classes inheriting from it and only overriding a few functions (something like an attack pattern).
However, it is a bit unsafe to do that since any parent function can be accidentally overridden by any of its children, which will break everything (potentially). This is especially problematic when multiple people are working on the same project.
I propose adding the following keywords:
final
- keyword that prohibits overriding of a functionabstract
- something like= delete;
in C++, orabstract
in C#. It might be a bit tricky to enforce, considering the dynamic nature of GDScript. However, I think throwing runtime error (or even warning) when attempting to instance class with deleted function is fineoverride
- same as C++/C#As another option, it might be better to allow overriding
final
functions when usingoverride
(however, in that case,final
should probably be changed to some other word).Beta Was this translation helpful? Give feedback.
All reactions