官术网_书友最值得收藏!

Leveraging encapsulation

What is encapsulation? Simply put, it is hiding the inner workings of a class that aren't necessary for the implementation of that class. Think of encapsulation as follows: most people who own a car know that it runs on gas- they don't need to know the inner working of an internal combustion engine to be able to use a car. They only need to know that they need to fill it up with gas when it is close to empty and that they need to check the oil and tyre pressure. Even then, it is usually not done by the car owner. This is true for classes and encapsulation.

The owner of the class is the one who uses it. The inner workings of that class need not be exposed to the developer using the class. The class is, therefore, like a black box. You know that the class will be consistent in its functionality, given the correct set of parameters. How exactly the class gets to the output is of no concern to the developer as long as the input is correct.

主站蜘蛛池模板: 竹山县| 柘荣县| 原阳县| 紫云| 射阳县| 沂源县| 平邑县| 万安县| 炎陵县| 沙洋县| 阳谷县| 南开区| 西宁市| 西昌市| 云龙县| 丹巴县| 三门峡市| 桃源县| 措美县| 寿宁县| 吴堡县| 舞钢市| 布尔津县| 赤壁市| 富民县| 珲春市| 微博| 蓬安县| 福鼎市| 湄潭县| 翼城县| 兰溪市| 云浮市| 海门市| 盐池县| 赣榆县| 颍上县| 桂平市| 建水县| 新龙县| 富顺县|