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

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.

主站蜘蛛池模板: 兴安县| 菏泽市| 城口县| 德昌县| 秀山| 潜江市| 长葛市| 边坝县| 华安县| 金沙县| 梅河口市| 长寿区| 乌鲁木齐县| 寿阳县| 陇南市| 绥阳县| 通化市| 白水县| 宜兴市| 通辽市| 大田县| 安龙县| 志丹县| 宜兰县| 长子县| 庆城县| 台中市| 兴宁市| 天津市| 大宁县| 忻城县| 开原市| 铜鼓县| 墨竹工卡县| 台中县| 文水县| 刚察县| 读书| 英超| 龙南县| 友谊县|