Information Hiding vs Encapsulation

        These are two of most important concepts in software design.But it is a pity there are no unified

definitions for the two concepts.

         These days I am reading the Code Complete 2nd Edition by Steve McCDonell.There are wonderful

points of these two concepts in the book.But personally I tend to enjoy the description from

       http://c2.com/cgi/wiki?InformationHiding

        The following description is copied from that link:

-----------------------------------------------------------------------------------------------------------------------------------

          InformationHiding is a principle first published by DavidParnas in his seminal paper

OnDecomposingSystems.

          The basic idea is that if code chunk A doesn't really need to know something about how code chunk B

(which it calls) does its job, don't make it know it. Then, when that part of B changes, you don't have to go

back and change A.

         It is widely recognized as the most important criterion for judging the quality of a software design, although

many more people think of it under a different name. The current phrase "if we do X we increase coupling

between A and B". Increasing coupling is equivalent with breaking InformationHiding.

        Encapsulation, strictly speaking, means something different; it means collecting a bunch of stuff together

and putting it in one box, or capsule. The box may or may not have opaque walls, so this may or may not

involve information hiding. In practice a "class" will both encapsulate (ie bundle code and data together)

and hide information (namely, implementation detail), and some people get so used to doing both at once

they no longer bother to distinguish. A few pedants still care, though.

----------------------------------------------------------------------------------------------------------------------------------------

        See the following links for more discussion:

         http://www.javaworld.com/javaworld/jw-05-2001/jw-0518-encapsulation.html

         http://www.toa.com/pub/abstraction.txt

   

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值