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

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.

主站蜘蛛池模板: 郴州市| 丽江市| 错那县| 个旧市| 岳西县| 西安市| 柳林县| 梁平县| 类乌齐县| 额尔古纳市| 澳门| 闽清县| 大冶市| 紫云| 江陵县| 洞口县| 衡阳县| 都江堰市| 固阳县| 家居| 瓮安县| 马关县| 万山特区| 军事| 海盐县| 金沙县| 亚东县| 女性| 澄江县| 周至县| 盐亭县| 卫辉市| 闵行区| 郓城县| 黑河市| 灵丘县| 宁波市| 江源县| 定州市| 乌兰察布市| 阿合奇县|