Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

A Question on Encapsulation

I know that encapsulation is binding the members and its behavior in one single entity. And it has made me think that the members have to be private. Does this mean if a class having public members is not following 100% Encapsulation rule?

Thanks

like image 730
bragboy Avatar asked Sep 06 '25 22:09

bragboy


1 Answers

Encapsulation is both data bundling and data hiding. Java allows you to expose data, but you should have a very good reason for it if you choose to do so. Member variables should be made private as a default, and only promoted to higher visibility if absolutely necessary.

like image 116
Bill the Lizard Avatar answered Sep 09 '25 05:09

Bill the Lizard