The Codeless Code: Case 3 Encapsulation(封装的意义)

目录

 

Original text

译文

启示


Original text

A young monk, new to the temple, not only declared all his methods public but all his instance variables as well. The head abbot grew weary of rebuking the monk and asked the Java master for advice.

The next day, the master summoned the monk to take lunch with him in his private office.

The monk entered to find a sumptuous meal laid out upon the conference table. The master then bade the monk to lie upon the floor.

The monk did as commanded, whereupon the master opened the monk’s robes and drew a large knife. He pressed the naked point firmly into the monk’s chest until a ruby droplet welled up around the blade. The monk cried out in terror and asked the master what his intention was.

“To slit open your belly,” explained the master, “so that I may spoon the rice and pour the tea inside. My schedule is quite full, and I find this method of feeding guests to be extremely efficient.”

Afterward the monk required no more correction.

 

译文

一个刚来到修道院的僧侣不仅公开声明了他的所有方法还公开声明了他所有的实例变量。主持对次非常的担心,斥责了这个僧侣,并请Java大师去给这个僧侣一些建议。 

第二天,大师传唤这个新来的僧侣到大师的私人办公室一起共用午餐。

僧侣一进去就发现会议桌上摆满了丰盛的食物。接着,大师命令这个僧侣躺到地板上去

这个僧侣按着大师的吩咐躺到了地板上,紧接着,大师解开了这个僧侣的僧袍并拿出了一把匕首。他把匕首朝着僧侣的胸部稳稳的插了进去,直到鲜红的血滴随着刀锋流了出来。这个僧侣惊恐的嘶喊着并质问大师究竟想干什么?

“这么做是为了切开你的肚子”,大师解释道,“只有这样我才能把给你的米饭和倒给你的茶给送进去,我的日程安排的很紧,所以,只有用这种方法我才能最高效的把食物塞道你肚子里去啊”

后来,这个僧侣就把他之前的习惯全改了

启示

编写的程序里如果没有封装,那使用这个程序的时候,无异于每次都要开膛破肚。

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值