Answer the question
In order to leave comments, you need to log in
How to name your properties and methods when inheriting from other classes?
Hello! How to name your properties and methods when inheriting from other classes in order to avoid conflict situations? Do not check before adding a new property / method whether there is a parent class with the same name? Yes, and there is no guarantee that something will not be added under this name later, for example, if we inherit the class of some popular library.
Answer the question
In order to leave comments, you need to log in
Do not check before adding a new property / method whether there is a parent class with the same name?
Inheritance is not recommended. If you inherit, then you impose on yourself the obligation to know what names are used and to monitor changes in the parent class.
Call it what you want. There will be no conflicts. But if the names match, then you can't override the implementation of the parent's method. If you do not need this polymorphism, then hammer it. And if needed, you already know the right name for the heir method.
Is it not necessary to read the documentation on the API used already? The compiler will throw an error if you override an already existing field.
A good IDE (such as InelliJ IDEA, for example) will check for this and point out errors. And so the question is not clear? What does "how to name" mean? By name convention + so that it is readable, short, concise, it is clear from the name what this method does.
And from adding methods to the parent class whose names will match the names of the methods in your heir, you are unlikely to somehow protect yourself. But there is not such a big chance that it will be. There are many names. In addition, your class must do something specific, specific part of your project, respectively, and the methods will be called that way. Methods of library classes are more general, universal. Therefore, they have corresponding names.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question