Java inheritance

In order to implement inheritance with Java, there is that marvellous word “extends”. From my point of view there is a commitment when we decide to extend from a class. First of all, the functionalities provided from the father class should work as expected. Also no secondary effects should happen. That means that the functionalities provided/added to the father class should not break the functionalities of the father if it does not make sense.

When using inheritance it could happen that all methods inherited from child class does not work as expected.

It happens that we extends from a class and implement new functionalities, in that case we should never forget to be sure that there is no conflict with the functionalities provided by the parent.

There is also another consequence that we have to keep in mind. If we want to mock, for example using Mockito, a class that extends from JavaFX, for example Service. In that case faking the answer to the method isRunning() would be not possible because is final.


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s