面向对象技术课件.ppt
- 【下载声明】
1. 本站全部试题类文档,若标题没写含答案,则无答案;标题注明含答案的文档,主观题也可能无答案。请谨慎下单,一旦售出,不予退换。
2. 本站全部PPT文档均不含视频和音频,PPT中出现的音频或视频标识(或文字)仅表示流程,实际无音频或视频文件。请谨慎下单,一旦售出,不予退换。
3. 本页资料《面向对象技术课件.ppt》由用户(三亚风情)主动上传,其收益全归该用户。163文库仅提供信息存储空间,仅对该用户上传内容的表现方式做保护处理,对上传内容本身不做任何修改或编辑。 若此文所含内容侵犯了您的版权或隐私,请立即通知163文库(点击联系客服),我们立即给予删除!
4. 请根据预览情况,自愿下载本文。本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
5. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007及以上版本和PDF阅读器,压缩文件请下载最新的WinRAR软件解压。
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 面向 对象 技术 课件
- 资源描述:
-
1、模式&框架Pattern & Framework2022-6-23Institute of Computer SoftwareNanjing University1摘要More about PatternFrameworkComparison2022-6-23Institute of Computer SoftwareNanjing University2摘要More about PatternFrameworkComparison2022-6-23Institute of Computer SoftwareNanjing University3More about PatternPatter
2、ns of PatternsAnti-patternJ2EE patterns2022-6-23Institute of Computer SoftwareNanjing University4More about PatternPatterns of PatternsAnti-patternJ2EE patterns2022-6-23Institute of Computer SoftwareNanjing University5Working togetherPatterns are often used together and combined with the same design
3、 solution.A compound pattern combines two or more patterns into a solution that solves a recurring or general problem.2022-6-23Institute of Computer SoftwareNanjing University6Example:设计一个文档编辑器设计问题文档结构格式化修饰用户界面支持多种视感(look-and-feel)标准支持多种窗口系统用户操作拼写检查和连字符2022-6-23Institute of Computer SoftwareNanjing
4、University7使用设计模式Composite表示文档的物理结构:递归组合Strategy允许不同的格式化算法Decorator修饰用户界面Abstract Factory支持多视感标准Bridge允许多个窗口平台Command支持撤销用户操作Iterator访问和遍历对象结构Visitor允许无限扩充分析能力而又不会使文档结构的实现复杂化2022-6-23Institute of Computer SoftwareNanjing University8Duck ExampleStart with a bunch of Quackables.A goose came along and
5、wanted to act like a Quakable too. Then, the Quackologists decided they wanted to count quacks.But the Quackologists were worried theyd forget to add the QuackCounter decorator.We had management problems keeping track of all those ducks and geese and quackables.The Quackologists also wanted to be no
6、tified when any quackable quacked.2022-6-23Institute of Computer SoftwareNanjing University9AdapterDecoratorAbstract factoryCompositeIteratorObserverCompound PatternsMVCa song about MVC by James Dempsey (lyrics)2022-6-23Institute of Computer SoftwareNanjing University10MVCMVC is a compound pattern c
7、onsisting of the Observer (model), Strategy (controller) and Composite (view) patterns.The Adapter pattern can be used to adapt a new model to an existing view and controller.2022-6-23Institute of Computer SoftwareNanjing University11Pattern Definition ReviewA Pattern is a solution to a problem in a
8、 context.Context: the recurring situation in which the pattern appliesProblem: the goal you are trying to achieve in this context and any constrains that occur in the context.Solution: a general design that anyone can apply which resolves the goal and set of constraints2022-6-23Institute of Computer
9、 SoftwareNanjing University12Pattern Categories I - GoalCreational Patterns: involve object instantiation and all provide a way to decouple a client from the objects it needs to instantiate.Structural Patterns: compose classes or objects into larger structures.Behavioral Patterns: concerned with how
10、 classes and objects interact and distribute responsibility2022-6-23Institute of Computer SoftwareNanjing University13Pattern Categories II - ScopeClass PatternsDescribe how relationships between classes are defined via inheritance. Relationships in class patterns are established at compile time.202
11、2-6-23Institute of Computer SoftwareNanjing University14Template MethodInterpreterAdapterFactory MethodPattern Categories II - ScopeObject PatternsDescribe relationships between objects and are primarily defined by composition.Relationships in object patterns are typically created at runtime and are
12、 more dynamic and flexible2022-6-23Institute of Computer SoftwareNanjing University15CompositeDecoratorVisitorCommandIteratorMementoProxyFacadeChain of ResponsibilityObserverBuilderSingletonPrototype FlyweightStateMediatorBridgeAbstract FactoryStrategyMore about PatternPatterns of PatternsAnti-patte
13、rnJ2EE patterns2022-6-23Institute of Computer SoftwareNanjing University16Anti-PatternsAndrew Koenig 1995, Michael Akroyd 1996An anti-pattern (反面模式) tells you how to go from a problem to a BAD solution.Tell you why a bad solution is attractive.Tell you why that solution in the long term is bad.Sugge
14、st other patterns that are applicable which may provide good solutions.2022-6-23Institute of Computer SoftwareNanjing University17Wiki反面模式分类组织结构的反面模式项目管理的反面模式团队管理的反面模式分析方式的反面模式一般设计上的反模式 面向对象设计的反面模式面向对象设计的反面模式编程上的反模式方法学上的反面模式测试反面模式配置管理反面模式2022-6-23Institute of Computer SoftwareNanjing University18Ane
15、mic Domain ModelBaseBeanCall superCircle-ellipse problemEmpty subclass failureGod objectObject cesspoolObject orgyPoltergeistsSequential couplingSingletonitiesYet another fucking layerYo-yo problemExample胖球反模式通过描述一个或几个类不断的膨胀,以至吞食掉整个面向对象架构。一般胖球的出现是由于一个类垄断了处理过程,而其他的类只是数据的封装体。症状和后果单个类拥有大量的属性或操作。单个类中封装了
16、异类的、不相关的属性和操作集。单个控制器类和几个简单的数据对象联系在一起。缺乏面向对象的设计,一个控制器类几乎封装了所有的应用功能。控制器类通常过于复杂,无法复用和测试。把这么个大类加载如内存中的代价可能会很高。 胖球反模式有两种形式:行为形式和数据形式。2022-6-23Institute of Computer SoftwareNanjing University19Example如何重构 (Refactor)把一些行为重新分配到某些封装了数据的对象上,并对对象之间的关系重新调整。确定代表契约的关系操作和属性集合,也就是把相关的属性和方法归类。寻找这些根据契约的到了集合的“自然的家”,并把
17、它们迁移过去。移除所有的“远耦合”或者说冗余的、间接的联系。最后,移除所有的瞬时联系。 总之,把一个控制器类变成了一个协调器类,让开始的总之,把一个控制器类变成了一个协调器类,让开始的数据类扩充一些处理逻辑,数据类在协调类的指导下进数据类扩充一些处理逻辑,数据类在协调类的指导下进行操作,这也只是职责的迁移。行操作,这也只是职责的迁移。2022-6-23Institute of Computer SoftwareNanjing University20More about PatternPatterns of PatternsAnti-patternJ2EE patterns2022-6-23I
18、nstitute of Computer SoftwareNanjing University21J2EE Patterns特点与平台、语言相关,描述的是J2EE平台上利用Java如何解决设计问题所解决问题的规模较大,在J2EE框架的基础上解决构件技术的选择、构件之间的协作等问题模式抽象层次较高,同时提供了若干具体实现的细节,称为策略策略。注重性能的优化2022-6-23Institute of Computer SoftwareNanjing University22J2EE Patterns Classification根据来源分为SJC设计模式和TheServerSide设计模式两大类J
19、2EE: JSP, Servlet, EJB, JMS, JDBC, JNDISJC (Sun Java Center)设计模式Web层模式:JSP,ServletIntercepting Filter, Front Controller, View Helper业务层模式:EJBBusiness Delegate, Value Object, Session Faade集成层模式:JMS,JDBCData Access Object, Service Activator2022-6-2323J2EE Patterns ClassificationTheServerSide设计模式EJB层体系
20、结构模式Session Faade, Message Faade, EJB Command层间数据传输模式Data Transfer Object, Data Transfer HashMap事务与持久性模式Version Number, JDBC for Reading客户端EJB交互模式EJB Home Factory, Business Delegate2022-6-23Institute of Computer SoftwareNanjing University24ExampleEJB调用是工厂模式的实现调用EJB 语法:EJBHome em = JNDIServer.getRemo
21、teHome(EJB-JNDI-NAME); EJBObject myEJB = em.create();em.create()类似Afactory.create();EJBObject 是接口2022-6-23Institute of Computer SoftwareNanjing University25Example会话 Bean和实体Bean: Faade模式一个会话Bean中调用多个实体Bean该会话Bean是一个Faade类/Manager类使用Faade 会话Bean优点:提供性能,节省客户端直接调用实体Bean的网络开销解耦分层,利于扩展变化。2022-6-23Institu
22、te of Computer SoftwareNanjing University26ExampleDTO(Data Transfer Object)模式DTO模式是指将数据封装成普通的JavaBeans,在J2EE多个层次之间传输。DTO类似信使,是同步系统中的Message该JavaBeans可以是一个数据模型Model2022-6-23Institute of Computer SoftwareNanjing University27ExampleMVC模式MVC模式是J2EE Web层的主要实现2022-6-23Institute of Computer SoftwareNanjing
23、 University28ExampleProxy模式代理模式可以强迫客户端对一个对象的方法调用间接通过代理类进行。通常代理模式有以下几种:访问代理(Access Proxy)、虚拟代理和远程代理远程代理等。动态Proxy模式动态代理利用Java的反射(Reflect)机制,可以在运行时刻将一个对象实例的方法调用分派到另外一个对象实例的调用。动态代理模式可以在运行时刻创建继承某个接口的类型安全的代理对象,而无需在代码编译时编译这些代理类代码。 2022-6-23Institute of Computer SoftwareNanjing University29J2EE Anti-Pattern
24、无EJB不叫J2EE过度分层 频繁的往返调用过度使用有状态的Session Bean过度会话万能Servlet或者万能JSP2022-6-23Institute of Computer SoftwareNanjing University30NowOO Design ToolboxOO BasicsOO PrinciplesOO PatternsYour patterns here!2022-6-23Institute of Computer SoftwareNanjing University31摘要More about PatternFramework: why, what, howCom
25、parison2022-6-23Institute of Computer SoftwareNanjing University32Forms of design-level reuseSharing of consistency: programming and scripting languageSharing concrete solution fragments: librariesSharing contracts: interfacesSharing individual architecture: patternsSharing subsystem architectures:
展开阅读全文