现代软件设计技术课件

上传人:我*** 文档编号:141920919 上传时间:2020-08-14 格式:PPT 页数:60 大小:258KB
返回 下载 相关 举报
现代软件设计技术课件_第1页
第1页 / 共60页
现代软件设计技术课件_第2页
第2页 / 共60页
现代软件设计技术课件_第3页
第3页 / 共60页
现代软件设计技术课件_第4页
第4页 / 共60页
现代软件设计技术课件_第5页
第5页 / 共60页
点击查看更多>>
资源描述

《现代软件设计技术课件》由会员分享,可在线阅读,更多相关《现代软件设计技术课件(60页珍藏版)》请在金锄头文库上搜索。

1、现代软件设计技术,潘爱民 ,内容,复习 Generic Programming 补充一些patterns 构造框架(framework)的技术 构造可重用类库的技术,复习:creational patters,Factory Method 本质:用一个virtual method完成创建过程 Abstract Factory 一个product族的factory method构成了一个factory接口 Prototype 通过product原型来构造product,Clone+prototype manager Builder 通过一个构造算法和builder接口把构造过程与客户隔离开 Si

2、ngleton 单实例类型,如何构造这单个实例?如何访问这单个实例? Finder 把对象的获取过程与客户隔离开,复习:Structural patterns,Adapter 、bridge、facade adapter用于两个不兼容接口之间的转接 bridge用于将一个抽象与多个可能的实现连接起来 facade用于为复杂的子系统定义一个新的简单易用的接口 composite、decorator和proxy composite用于构造对象组合结构 decorator用于为对象增加新的职责 proxy为目标对象提供一个替代者 flyweight 针对细粒度对象的一种全局控制手段,复习:Behav

3、ioral Patterns,Command 用对象封装命令,使得命令可以被传递、记录、排队等 Iterator 把对聚合体对象的访问封装起来 Observer 建立起一对多的通信模型,特别适合于更新通知和事件模型 Strategy 把一个对象或者类的某些行为封装到另一个单独的对象中 Visitor 把对一个结构模型的操作单独组织到一个类中,复习:Behavioral Patterns(续一),Chain of Responsibility 请求的处理过程,沿着链传递,decouple发送方和接收方 Interpreter 在类层次结构中,在特定环境的“interpret”过程 Mediato

4、r 用一个mediator来decouple各同等单元 Memento 在对象之外保存对象的内部状态 State 把一个对象的状态独立出来,动态可变换状态对象的类型 Template Method 在基类中定义算法的骨架,把某些细节延迟到子类中,复习:Behavioral Patterns(续二),Strategy、Iterator、Mediator、State、command 用一个对象来封装某些特性,比如变化、交互、状态、行为、命令 Mediator、Observer Observer建立起subject和observer之间的松耦合连接 mediator把约束限制集中起来 -中心控制 c

5、ommand、Chain of Responsibility、interpreter command模式侧重于命令的总体管理 Chain of Responsibility侧重于命令被正确处理 interpreter用于复合结构中操作的执行过程,Generic programming,思想: “通过参数化技术达到重用的目的(reuse through parameterization)”,使得组件更容易被定制。实现静态配置代码,从而获得很高的效率。 Generic Programming可以消除类型和算法之间本来不必要的相依性 STL是成功的generic programming典型 gene

6、ric programming限制代码产生的方式:用实体类型代替类型参数,使这些预先编制好的代码模型成为真正的代码,无法产生完全新的代码。,相关的programming,Aspect-Oriented Programming (AOP) An aspect is a modular unit that cross-cuts the structure of other modular units Aspects exist in both design and implementation. A design aspect is a modular unit of the design tha

7、t cross-cuts the structure of other parts of the design. A program or code aspect is a modular unit of the program that cross-cuts other modular units of the program. 把问题分解为功能单元(组件)和aspect 在AOP系统中,组件和aspects(交织)组合起来得到一个系统的具体实现。交织组合既可以在compile-time,也可以在runtime AOSD, 参考:,generative programming,Generat

8、ive Programming 建立起一族软件系统的模型,在特定的要求下,利用一些基本的、可重用的组件,通过配置,能够自动根据需要产生一个高度定制和优化的软件系统实例 一些原则 用参数化技术来概括出差异性 对于相依性和交互进行分析和建模 通过静态链接(compile-time)消除不必要的开销,以及执行与特定领域相关的优化 将问题空间和方案空间分离,通过配置建立两者的映射关系 Separation of concerns: borrowed from AOP 特点 Generative Programming涉及到软件开发过程的各个阶段 与Domain Engineering结合 A Mode

9、l-Based Approach:http:/www.sei.cmu.edu/domain-engineering/domain_engineering.html Active Libraries,C+ Generic Programming,Template技术 使C+成为two-level language metaprogram 从科学计算用途-一般性的抽象,即generic programming 对于编译器 代码产生、优化 在编译时刻,实现静态绑定 partial evaluation 对于库开发人员 Active libraries,提供一种抽象的功能,并且控制优化过程 许多技术,

10、如policy(traits)、编译时刻计算功能 对于应用开发人员 定制template class或者template function,C+ Generic Programming(续),设计思想 编译时刻程序设计,类似于logic-programming即,在compile-time让编译器完成一些功能,例如 静态的计算功能 if/else,loop,switch 对type进行一些基本的逻辑操作(编程) 保证类型安全 宁可要compile-time error,也不要runtime error 尽可能地泛化 抽象性 跟传统的设计方法结合起来,比如利用patterns,Template基

11、础 class template,template class Array public: T,使用: Array a1; Array a2;,Template基础 模板特化template specialization,template class Array public: char,Template基础 部分模板特化 partial template specialization,template class Array public: T *Visual C+ 6不支持部分模板特化,Template基础 函数模板function template,template void Swap(

12、T ,模板参数,compile-time起作用,函数参数,runtime起作用,Template基础 函数对象泛化generalized functors(function objects),functor:重载了operator()的C+对象,扩展了函数指针的概念,可以增加内部状态,可以被当作对象来传递,具有值语义(value semantic)。它可以是template class,也可以不是 template class Functor public : ResultType operator()(); / other member function private : / implem

13、entation ; 用法: Functor MyFunctor(val1); int Result = MyFunctor();,Template技术 代替runtime的if/else,/ Class declarations template class ConditionProcess ; class ConditionProcess public: static inline void f() statement1; / true case ; class ConditionProcess public: static inline void f() statement2; / fa

14、lse case ; / Replacement for if/else statement: ConditionProcess :f();,if (condition) statement1; else statement2;,Compile-time能够确定condition的值,Template技术 代替runtime的switch,/ Class declarations template class SwitchProcess public: static inline void f() default-statement; ; class SwitchProcess public:

15、 static inline void f() statement1; ; class SwitchProcess public: static inline void f() statement2; ; / Replacement for switch(i) statement SwitchProcess :f();,int i; switch(i) case value1: statement1; break; case value2: statement2; break; default: default-statement; break; ,Template技术 代替runtime的d

16、o循环,template class DoProcess private: enum go = (I-1) != 0 ; public: static inline void f() statement; DoProcess :f(); ; / Specialization provides base case for recursion class DoProcess public: static inline void f() ; / Equivalent loop code DoProcess :f();,int i = N; do statement; while (-i 0);,Template技术 代替runtime的临时变量,template class countBits enum bit3 = (N ,int countBits(int N) int bit3 = (N ,Template技术 计算 Compile-time funct

展开阅读全文
相关资源
正为您匹配相似的精品文档
相关搜索

最新文档


当前位置:首页 > 办公文档 > PPT模板库 > PPT素材/模板

电脑版 |金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号