Thursday 28 March 2019

Did you ever do this?

So I was working on a class which was too big. Time to pull it apart into helper classes (in the same package). Then I noticed a number of methods were protected.

Now protected means it can be both accessible from subclasses as well as classes in the same package. (That last part is often forgotten by me.)

Which means when pulling things apart into classes, I can simply call these protected methods. Yay!

Unfortunately, these protected methods were defined in a superclass and the superclass was declared in... you guessed it... a different package.

The ugly hack that solved this is the following:

Of course, I deleted this, because to my mind overriding a method, just to increase the visibility is a huge code-smell. (Or isn't it?)

But I was wondering if anyone else ever did this? (due to time pressures and not being able to change the super class, etc.)

And what would be a more pretty work around, if you have one?

No comments:

Post a Comment