I usualy declare my classes public. When does it make sense to declare a class private?
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
You can only declare a class as private when it’s nested within another class. Top-level classes can be made internal, however.
You’d hide a class from the outside world when it’s meant to be an implementation detail rather than providing an API everyone can use. The downside is that the outside world can’t use that code directly even if it would be useful to them – the upside is that you can change the class however you like in the future without breaking the rest of the world, so long as your public API remains the same in both shape and behaviour.