《面向对象设计 》PPT课件.ppt
《《面向对象设计 》PPT课件.ppt》由会员分享,可在线阅读,更多相关《《面向对象设计 》PPT课件.ppt(38页珍藏版)》请在三一办公上搜索。
1、第十一章 面向对象设计(Object-Oriented Design),1.OOD准则:优秀软件设计的一个重要特点是容易维护,回顾:SD准则包括 Modularization Abstraction Information hiding Module independence,对于 OOD有类似的准则:1、Module=Object,1.OOD准则,Procedure abstraction:在SD中已讨论,Data abstraction:Class即是一种抽象数据类型。外界无须知道实现方法就可按照类协议(class description protocol)*使用class中定义的数据。,
2、Parameter abstraction:将数据类型作为参数处理。,*Class description protocol:The complete definition of all properties,features,and methods that are descriptive of any object that is an instance of a class.Timothy Budd An Introduction to Object-Oriented Programming Addison-Wesley Publishing Company,Inc.1991,2、Abs
3、traction:抽出事物的本质特性,暂不考虑其细节,使设计从具体实现方法中超脱。,1.OOD准则,例:C+中的“模板”(template),template class array_n private:T items n;/定义了T类型的向量元素共n个;main()array_n w;/w是有1000个元素的复向量,1.OOD准则,3、Information hiding=Encapsulation of object,继承耦合(inheritance coupling):要求 Parent class IS_A child class as high as possible,1.OOD准则
4、,一般-特殊内聚(general-particular cohesion):High g-p cohesion High inheritance coupling,5、Cohesion:服务内聚(service cohesion):一个服务只完成一个功能。,类内聚(class cohesion):一个类只有一个用途,否则分解之。,6、Reusability(详见3),2.启发式规则,1、设计结果清晰易懂,应做到:用词一致 按习惯用法命名。不同classes中相似的methods最好取同一名字。使用已有的protocol。尽量减少message模式的数目。避免模糊定义。,2、一般-特殊结构的深度
5、应适当(约100个classes,则设计72层),2.启发式规则,3、设计简单的class(定义不超过一页纸或两屏)。应注意:避免过多attributes;能用简单的语句描述一个class的任务;objects之间合作关系要简单;避免过多methods(7个)。,问题:设计出大量的classes,使结构复杂度增加。解决:划分主题,提高可理解性。,4、使用简单的protocol,减少message 中传递的 parameters,5、使用简单的method(CASE 可考虑用 inheritance替代)。,6、把设计变动减至最小。,1、概念:知识重用(例如软件工程知识的重用),方法和标准重用(
6、例如OO方法和国家规定的软件开发规范的重用),软件成分的重用,3.软件重用(Software Reuse),源码剪贴 无法溯源,无配置管理,Include 修改后所有包含了此段代码的程序都须重新编译。,Inheritance 无须改动原有代码,想象一下,stdio.h 被改动之后,重用软件成分有三个级别:代码重用:,3.软件重用,设计重用 当移植系统时,分析重用 当需求未变,而系统结构改变时(例如将HDIS改为OO实现),2、重用效果的衡量:,额外代价:创建可重用成分的专门投资 多花2 4倍时间测试以保证质量 构件库的建立与维护需要投资 以上投资将分摊到重用这些构件的新系统成本中。重用次数越多
7、,分摊成本越少。,3.软件重用,记:Lt=Total length of code(#of lines)Ln=Length of new code Lr=Length of reused code Et、En、Er are the corresponding efforts(#of m-d),重用率(Reusability)与生产率(Productivity),Productivity,Reusability=,开发代码的生产率,重用新代码的生产率,3.软件重用,重用技术:指利用可重用的构件开发软件的技术,及开发可重用软件的技术。,软件组合技术:,底层部件库法(Bottom-up compos
8、itional reuse):从可重用的代码部件库(reuse repository)中选用部件,组合成软件。,A:是,前提条件为CnCr,即重用比新开发效率高。,Q:是否R 越高P就越高?,Lucent Technologies initiated a companywide program to reuse software components(McClure 1997).As a consequence,the Workstation Software Development Department formed a Reuse Council to devise a strategy
9、for selecting candidate components for its reuse repository.The Council was comprised of seven people,representing all groups in the department.The Council created an inventory of components and formed a matrix with the features of all past and planned projects.Then,each feature was rated in terms o
10、f whether it had been implemented and was still needed,had been implemented but was no longer needed,or had not been implemented but was still needed.Those features that were needed and were common to more than one project were targeted for reuse.In fact,some were redesigned to make them more reusab
11、le.The Council met every week for 2 hours to make component selections,inspect design documentation for those components already in the repository,and to monitor the levels of reuse in the departments projects.,3.软件重用,例:,上层组合法:完整程序的组合,3.软件重用,软件生成技术:按照形式化的软件功能描述和一定的生成机理,由生成器系统(generator system)自动生成目标
12、程序。重用的是generator 的代码规则,OO重用技术:Class component的重用(详见下文),类构件(Class component):,可重用的软构件应具备的特点:独立、可塑、接口清晰(文档详尽),3.软件重用,重用方式:实例重用(instance reuse black-box reuse):创建class的不同instances,通过messages完成 不同的任务。是最基本的重用方式。用几个简单的objects创建出更复杂的class,是实例重用的另一种形式,继承重用(inheritance reuse):是一种安全地裁剪已有的class component的方式。,多
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 面向对象设计 面向对象设计 PPT课件 面向 对象 设计 PPT 课件

链接地址:https://www.31ppt.com/p-5619410.html