X
X
Xveeder2018-05-19 19:15:48
C++ / C#
Xveeder, 2018-05-19 19:15:48

Correct use of virtual, override, new?

Good day, comrades. To business.
When designing a class, we do not always know which methods we will have to override in the future. Does this mean that all methods should be made virtual? Or you can get by with new to override.
I know about the context of new and override. But it seems to me that in general it is more correct to use override, because it behaves more expectedly.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
E
eRKa, 2018-05-19
@Xveeder

Does this mean that all methods should be made virtual?

No, it doesn't. If you allow to redefine everything, then you can break the logic. And if you write a library and allow everything and everyone to change? Overriding can be allowed in places where the strategy is used: where there is a generic class and inherited classes can implement their own logic.
If suddenly, during the development process, it becomes necessary to allow overriding, then it will not take long to add override.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question