-软件工程-15-面向对象信息隐藏课件.ppt
- 【下载声明】
1. 本站全部试题类文档,若标题没写含答案,则无答案;标题注明含答案的文档,主观题也可能无答案。请谨慎下单,一旦售出,不予退换。
2. 本站全部PPT文档均不含视频和音频,PPT中出现的音频或视频标识(或文字)仅表示流程,实际无音频或视频文件。请谨慎下单,一旦售出,不予退换。
3. 本页资料《-软件工程-15-面向对象信息隐藏课件.ppt》由用户(三亚风情)主动上传,其收益全归该用户。163文库仅提供信息存储空间,仅对该用户上传内容的表现方式做保护处理,对上传内容本身不做任何修改或编辑。 若此文所含内容侵犯了您的版权或隐私,请立即通知163文库(点击联系客服),我们立即给予删除!
4. 请根据预览情况,自愿下载本文。本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
5. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007及以上版本和PDF阅读器,压缩文件请下载最新的WinRAR软件解压。
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 软件工程 15 面向 对象 信息 隐藏 课件
- 资源描述:
-
1、计算与软件工程II Ch15 “面向对象”的信息隐藏丁二玉南京大学软件学院Information Hiding nEach module hides the implementation of an important design decision (secrets) so that only the constituents of that module know the details3Design Secrets need to hidenPrimary Secret: Responsibility ChangenHidden information that was specifie
2、d to the software designernFrom SRSnSecondary Secret: Implementation ChangenThe implementation decisions made by the designer when implementing the module designed to hide the primary secretn变化;Main Contents1.Encapsulation1.What should be hiding?2.How to hiding change?Encapsulation (1)nEncapsulation
3、 allows the programmer to group data and the subroutines that operate on them together in one placenResponsibilityEncapsulation (2)nhide irrelevant details from the user na class can be divided into two parts, the user interface and the implementation.nThe interface is the visible surface of the cap
4、sule.qdescribes the essential characteristics of objects of the class which are visible to the exterior worldnThe implementation is hidden in the capsule.qThe implementation hiding means that data can only be manipulated, that is updated, within the class, but it does not mean hiding interface data.
5、New View of EncapsulationnOld/Beginner/Implementation view of encapsulation: hiding data inside an objectnNew view: hiding anything, including:qData (implementation)qStructure (implementation)qOther object (implementation)qType (derived classes)qChange/vary (design details)qEncapsulation Correctly A
6、DTnADT = Abstract Data TypeqA concept, not an implementationqA set of (homogeneous) objects together with a set of operations on those objectsqNo mention of how the operations are implementednEncapsulation = data abstraction + typeqdata abstraction: group data and operationqType: hiding implementati
7、on, make usage correctly Why type?nA type may be viewed as a set of clothes (or a suit of armor) that protects an underlying untyped representation from arbitrary or unintended use. nIt provides a protective covering that hides the underlying representation and constrains the way objects may interac
8、t with other objects. nIn an untyped system untyped objects are naked in that the underlying representation is exposed for all to see.Encapsulate DatanIf needed, use Accessors and Mutators, Not Public Members nAccessors and Mutators is meaningful behaviorqConstraints, transformation, formatpublic vo
9、id setSpeed(double newSpeed) if (newSpeed 0) sendErrorMessage(.);newSpeed = Math.abs(newSpeed);speed = newSpeed;Encapsulate structuresnSee chapter 16 Iterator PatternReferences and Collection Data-Type !Encapsulate other objectsnCollaboration DesignqComposition; delegationEncapsulate type(subclass)n
10、LSPqpointers to superclasses or interfaces;All derived classes must be substituteablefor their base classEncapsulate Change (or vary)nIdentify the aspects of your application that may change (or vary) and separate them from what stays the same. nTake the parts that change( vary ) and encapsulate the
11、m, so that later you can alter or extend the parts that vary without affecting the parts that dont. nSee DIP and OCP LaterEncapsulate Implementation DetailnData nStructurenOther objectnTypenChange/varynPrinciple #1: Minimize The Accessibility of Classes and MembersnAbstractionqAn abstraction focuses
12、 on the outside view of an object and separates an objects behavior from its implementationnEncapsulationqClasses should not expose their internal implementation detailsMain Contents1.Encapsulation2.How to hiding change?Example of Responsibility ChangeCopyReadKeyboardWritePrintervoid Copy(ReadKeyboa
13、rd& r, WritePrinter& w) int c; while (c = r.read () != EOF) w.write (c);WriteDiskvoid Copy(ReadKeyboard& r, WritePrinter& wp, WriteDisk& wd, OutputDevice dev) int c; while(c = r.read()!= EOF) if(dev = printer) wp.write(c); else wd.write (c);How to nAbstraction is Keyq.using polymorphic dependencies
展开阅读全文