Encapsulation vs Data Hiding - Java

前端 未结 19 2089
耶瑟儿~
耶瑟儿~ 2020-12-04 08:29

Interviewer: What is encapsulation and how do you achieve it in Java?

Me: Encapsulation is a mechanism to hide

19条回答
  •  旧巷少年郎
    2020-12-04 08:55

    The way i see it , Encapsulation refer to the idea of binding data and method to a single unit called class . However there are two main criteria to bind data and methods . One of them is information hiding, just not the only one . To be perfectly concise i would say the two main criteria are

    1. Low Coupling (ensure by information hiding)
    2. High Cohesion

提交回复
热议问题