Information Hiding vs Encapsulation

王朝other·作者佚名  2006-01-09
窄屏简体版  字體: |||超大  

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

 
 
 
免责声明:本文为网络用户发布,其观点仅代表作者个人观点,与本站无关,本站仅提供信息存储服务。文中陈述内容未经本站证实,其真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
 
 
© 2005- 王朝網路 版權所有 導航