Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

It's not a security thing, simply a housekeeping thing. It is more readable and understandable if an object only exposes the methods that it's user needs. It's about reducing complexity.

I think in Java you actually can access the private methods of an object via Reflection, if you absolutely want to.



"It is more readable and understandable if an object only exposes the methods that it's user needs."

This sort of encapsulation is not specific to OO. You can hide data and methods within modules without using classes. In C++ terms you use anonymous namespaces. In C, perl, python(?) and other languages a leading underscore or "static" declaration conveys encapsulation, which is good enough as far as I'm concerned.




Consider applying for YC's Winter 2027 batch! Applications are open till November 2.

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: