Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why are some classes not public in the Android Support Library?

Why are some of the classes included in Android's Libraries not public? To me this makes no real sense and basically just introduces a barrier to developing temporary fixes to some of the bug-riddled widgets that have recently been released.

Specifically I'm talking about the TextInputLayout in the Android Design Support Library. For example if I want to make a custom widget which overrides some of the code in the constructor I can't do that because CollapsingTextHelper is not a public class. I would have to download the source code and copy the relevant classes to my project, but there isn't really anything that is preventing me from doing that anyway. So what's the point of not making it public in the first place?

As I understand it as a library gets updated and improved over time you can just add the @Deprecated annotation to indicate that a specific class is old or outdated and is only still around to prevent legacy code from breaking.
I know that it makes no sense for a library to simply make all classes public, but I don't understand why classes essential to the implementation of a widget shouldn't be public. Why can't they just add the @Deprecated annotation when one of the classes is replaced by a better version, or when widgets are implemented in a different way altogether?

like image 774
charliebeckwith Avatar asked Dec 04 '25 09:12

charliebeckwith


1 Answers

In short - by making those classes non-public they're reserving the right to change/delete this class at any time without breaking any client's (your) code.

Look at how many @Deprecated methods/classes there are already and you'll see why this is important.

like image 188
Dmitry Zaytsev Avatar answered Dec 05 '25 23:12

Dmitry Zaytsev