This question already has an answer here:
I have read a few asserts vs exception questions already; I ask specifically about package visible classes though.
When you write a package, the classes marked with "public" are exposed to the outside world, thus exceptions are used to let users of the package's interface know they're using the package wrong.
The classes that are left unmarked are only exposed to the internals of the package, no? So I'm inclined to say that when something goes awry in a package visible class, assertions would be used stop the classes I have built from sending one another bad data.
Is this a fine thing to do?
I have adopted the idea that objects hold their own data as private to them and methods are public/private as needed to work internally or with other classes. Once the class is identified as doing too much, the class is split into simpler objects meant to work together.
At this point, many classes exist, but only some should be exposed to the outside world. So I have reached the conclusion that packages are like super objects, exposing just enough so that the entire "community" of classes can work together to solve the problem. This way implementation is hidden but a service is still provided.
Is that understanding correct? That is what the question is based on, since the community of classes is created in a "private to the package" manner, it is not exposed to the outside, and so, should assertions be used instead?