• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

default/protected asserts?

 
Hans Beck�rus
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
- Do no use assertions to validate arguments to a public method
- Do use assertions to validate arguments to a private method

So far so good when it comes to appropiate use of assert, but what about the "in betweeners", default and protected. Are there any best-practice (official) mentioned somewhere about those two?
I personally would say that protected should be classified as public since you as a programmer can not tell if a class will be sub-classed by a class in another package. When it comes to default access I guess it could be classified as a private method since I guess most commonly you have full control of the current package during development.

Does anyone have any experience about what could be the "correct" definition? Could protected and default be mentioned in the exam
as to their "appropriateness" when it comes to argument validation?
 
Barry Gaunt
Ranch Hand
Posts: 7729
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have not seen any offical mention of use of assertions in "default" or protected methods. I do not recall anything in the "Programming for Assertions" document. I tend to agree with your analysis above.

For SCJP I guess it will be always a choice from the two extreme cases: public or private.
 
Hans Beck�rus
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Barry Gaunt:
For SCJP I guess it will be always a choice from the two extreme cases: public or private.


Thanks Barry, then I will stick with my own "definition" for the other cases. Though, default may be debateble, but I guess thats exactly the
reason for Sun not mentioning anything about them, it may be like telling
someone where to put the brackets
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic