D
D
Donald_Duck2018-08-04 22:27:12
Programming
Donald_Duck, 2018-08-04 22:27:12

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

6 answer(s)
E
Evgeny Romashkan, 2018-08-04
@EvgeniiR

Do not check before adding a new property / method whether there is a parent class with the same name?

Why not check? + IDE should automatically suggest such things.
Well, for good, if you already inherit from something, you need to understand why you are doing it, and still have an idea about the parent structure

Y
Yan-s, 2018-08-04
@Yan-s

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.

G
Griboks, 2018-08-04
@Griboks

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.

X
Xilian, 2018-08-05
Xilian

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.

E
eRKa, 2018-08-04
@kttotto

Use namespaces.

M
MaxLich, 2018-08-06
@MaxLich

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 question

Ask a Question

731 491 924 answers to any question