A
A
Alksar2015-04-20 20:42:14
OOP
Alksar, 2015-04-20 20:42:14

Does a class inherit a method that it shouldn't implement?

Such a situation, let there be a class tree, heirs are inherited from the parent. At some point in time, a new method is added to the parent class. Now the heirs should automatically override it for themselves. But what if for some successor such a method does not make sense? Throw an exception? To do nothing? Or maybe redesign the class system to avoid such a situation? How do they usually do it?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Alexey Ukolov, 2015-04-20
@Alksar

This is a violation of the interface separation principle .
How significant it is in your particular case, only you can decide, but in general, the fact that you have to break SOLID speaks of design errors.

I
IceJOKER, 2015-04-20
@IceJOKER

I think you need to read about design patterns.
If the parent class is abstract and the method too, then it is necessary to overload the method in the heirs, otherwise you can put a stub in the parents, and override the rest, then in some heirs you can omit the overload.
Read more about design patterns

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question