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

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.

主站蜘蛛池模板: 普洱| 南昌市| 锦州市| 共和县| 新营市| 措美县| 搜索| 深水埗区| 宣化县| 苍山县| 湘潭县| 松阳县| 铁力市| 太保市| 铜山县| 库尔勒市| 鹿邑县| 汾西县| 平远县| 迁安市| 昌乐县| 湟中县| 石家庄市| 宁强县| 呼和浩特市| 天祝| 沽源县| 东丰县| 乐安县| 永德县| 科技| 漳浦县| 南宁市| 若羌县| 汤原县| 巴中市| 元氏县| 视频| 大渡口区| 巴马| 富顺县|