Why you need to know if an abstract class method is abstract

I was asked a question. This is the following:

The API documentation of the abstract class indicates whether the method is abstract. When and why do you need to know this?

Any help would be appreciated.

+4
source share
4 answers

You need to know which methods are abstract, because you will need to provide implementations of these methods when you inherit a class.

+9
source

As an extension to Fredrik's answer, he also indicates what behavior should be changed.

You can usually override a method (if this method is not final and the class is not final), but in practice it can be very difficult if the class is not specifically designed for changes. It is possible that existing methods assume some kind of behavior of a method that you override, which is not specified (this happens) and which you do not provide.

By explicitly declaring a method abstract, you express the intention that the method will be implemented by someone else. It also usually means that the documentation of the abstract method is a bit more complete regarding the expected behavior.

+2
source

If you call an abstract method, you need to take into account that the actual implementation is in a different place and may have some changes in behavior.

0
source

you know whether the method is abstract, because in this case you have to implement it in your concrete (inherited) class.

I advise you to take a look at the following books about Design Patterns, because they mention these things and have practices too:

http://oreilly.com/catalog/9780596007126

0
source

All Articles