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

Encapsulating to protect

Earlier in this chapter, we defined encapsulation as the hidden nature of an object's data. Granting access to an object's data via its own accessors and mutators is a great approach to data protection.

We use encapsulation as an approach to data protection in OOP. Encapsulating too much data into a class is an anti-pattern—something that should be avoided. As with the create concise objects approach, we should identify what data all copies of an object have in common and only encapsulate those data elements. Other data might be better suited for an ancillary class.

主站蜘蛛池模板: 虹口区| 盘山县| 阳春市| 神农架林区| 济南市| 阿鲁科尔沁旗| 精河县| 湘阴县| 藁城市| 光泽县| 罗定市| 五峰| 南昌县| 宜阳县| 理塘县| 莱西市| 汉阴县| 都兰县| 伊春市| 南召县| 察隅县| 托里县| 台东县| 湾仔区| 青河县| 阿荣旗| 呼伦贝尔市| 朝阳市| 石嘴山市| 平山县| 潼关县| 卫辉市| 五常市| 玉屏| 汉川市| 五原县| 凯里市| 海林市| 沙坪坝区| 三河市| 睢宁县|