91

面向对象之封装(day7)-沐梓琼-51CTO博客

 6 years ago
source link: http://blog.51cto.com/10630401/2066428
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
一、引子从封装本身的意思去理解,封装就好像是拿来一个麻袋,把小猫,小狗,小王八一起装进麻袋,然后把麻袋封上口子。照这种逻辑看,封装=‘隐藏’,当然,这种理解是相当片面的。二、先看如何隐藏在python中用双下划线开头的方式将属性隐藏起来(设置成私有的)其实这仅仅这是一种变形操作且仅仅只在类定义阶段发生变形,类中所有双下划线开头的名称如__x都会在类定义时自动变形成:_类名__x的形式:classA

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK