lexi设计案例分析.ppt
《lexi设计案例分析.ppt》由会员分享,可在线阅读,更多相关《lexi设计案例分析.ppt(76页珍藏版)》请在课桌文档上搜索。
1、1,第2章 实例研究:Lexi 文档编辑器,A WYSIWYG document editor.Mix text and graphics freely in various formatting styles.The usualPull-down menusScroll barsPage icons for jumping around the document.通过本实例设计,学习设计模式的实际应用,2,2.1 设计问题,Lexi设计的7个问题1 文档结构:对文档内部表示的选择几乎影响Lexi设计的每个方面。2 格式化3 修饰用户界面4 支持多种视感标准5 支持多种窗口系统6 用户操作7
2、拼写检查上述每个问题都有一组相关联的目标集合和限制条件集合。,3,2.2 文档结构,目标保持文档的物理结构。即将文本和图形安排到行、列和表等。可视化生成和显示文档。根据显示位置来映射文档内部表示的元素。限制条件应该一致地对待文本和图形。应该一致地对待简单元素和复合元素。但文本分析依赖于被分析对象的类型。,4,解决方案:递归组合,递归组合:Building more complex elements out of simpler ones.行列(段落)页(P24 第2段第2行)第5行第2列的第10个元素 The tenth element in line five of column two,隐
3、含:Each object type needs a corresponding classAll must have compatible interfaces(inheritance),图2 包含正文和图形的递归组合,图3 递归组合的对象结构,5,Glyph(图元类),Base class for composable graphical objectsAn Abstract class for all objects that can appear in a document.Both primitive and composed.,子类:Character,Image,Space,Ro
4、w,Column,6,图元类层次,Note the inherent recursion in this hierarchyi.e.,a Row is a Glyph&a Row also has Glyphs!,7,Glyph Interface and responsibilities,Glyphs know how to draw themselvesGlyphs know what space they occupyGlyphs know their children and parents,public abstract class Glyph/appearance public a
5、bstract void draw(Window w);public abstract Rect getBounds();/hit detection public abstract boolean intersects(Point);/structure public abstract void insert(Glyph g,int i);public abstract void remove(Glyph g);public abstract Glyph child(int i);public abstract Glyph parent();,8,COMPOSITE 模式 object st
6、ructural,意图treat individual objects&multiple,recursively-composed objects uniformly适用objects must be composed recursively,and no distinction between individual&composed elements,and objects in structure can be treated uniformly,Structure,9,COMPOSITE 模式(contd)object structural,效果uniformity:treat comp
7、onents the same regardless of complexityextensibility:new Component subclasses work wherever old ones do实现do Components know their parents?保持从子部件到父部件的引用能简化组合结构的遍历和管理uniform interface for both leaves&composites?最大化Component接口dont allocate storage for children in Component base classresponsibility for
8、 deleting children由Composite负责删除其子节点,10,2.3 格式化,格式化:将一个图元集合分解为若干行目标:自动换行Breaking up a document into lines.Many different algorithmstrade off quality for speedComplex algorithms限制条件Want to keep the formatting algorithm well-encapsulated.independent of the document structurecan add formatting algorith
9、m without modifying Glyphscan add Glyphs without modifying the formatting algorithm.Want to make it dynamically changeable.,11,Composition&Compositor,Compositorbase class abstracts linebreaking algorithmsubclasses for specialized algorithms,e.g.,SimpleCompositor,TeXCompositor接口格式化内容:void SetComposit
10、ion(Composition*)格式化:virtual void Compose()Compositioncomposite glyphsupplied a compositor&leaf glyphscreates row-column structure as directed by compositor,12,Composition&Compositor,一个未格式化的Composition对象只包含组成文档基本内容的可见图元,它并不包含像行和列这样决定文档物理结构的图元。Composite对象只在刚被创建并以待格式化的图元进行初始化后的状态当Composition对象需要格式化时,调
11、用它的Compositor的Compose操作。Compositor依次遍历Composition的各个图元,根据分行算法插入新的行和列图元。,Generated in accordance with compositor strategies&do not affect contents of leaf glyphs,13,Compositor&Composition,Compositor class will encapsulate a formatting algorithm.,Strategy,14,Compositor&Composition,分行算法封装能增加新的Composito
12、r子类而不触及Glyph类可在运行时刻改变分行算法在Composition接口中增加一个SetCompositor操作,15,STRATEGY模式 object behavioral,意图define a family of algorithms,encapsulate each one,&make them interchangeable to let clients&algorithms vary independently适用性when an object should be configurable with one of many algorithms,and all algorit
13、hms can be encapsulated,and one interface covers all encapsulations,结构,16,STRATEGY模式(contd)object behavioral,效果greater flexibility,reusecan change algorithms dynamicallystrategy creation&communication overheadinflexible Strategy interfacesemantic incompatibility of multiple strategies used together实
14、现exchanging information between a Strategy&its contextstatic strategy selection via templates,17,2.4 修饰用户界面,Wish to add visible borders and scroll-bars around pages.Inheritance is one way to do it.leads to class proliferationBorderedComposition,ScrollableComposition,BorderedScrollableCompositioninfl
15、exible at run-timeWill have classesBorderScrollerThey will be Glyphsthey are visibleclients shouldnt care if a page has a border or notThey will be composed.but in what order?,18,2.4 修饰用户界面,目标:add a frame around text compositionadd scrolling capability限制条件:embellishments should be reusable without s
16、ubclassing,i.e.,so they can be added dynamically at runtimeshould go unnoticed by clients,19,解决方案:“Transparent”Enclosure(透明围栏),Monoglyph:起修饰作用的图元的抽象类base class for glyphs having one childoperations on MonoGlyph pass through to childMonoGlyph subclasses:Frame:adds a border of specified widthScroller:
17、scrolls/clips child,adds scrollbars,20,MonoGlyph,Border calls MonoGlyph.draw();drawBorder();,Decorator,21,Transparent Enclosure,single-child compositioncompatible interfacesEnclosure will delegate operations to single child,but canadd stateaugment by doing work before or after delegating to the chil
18、d.,22,DECORATOR 模式 object structural,意图augment One object with new responsibilities适用性when extension by subclassing is impracticalfor responsibilities that can be withdrawn,Structure,23,DECORATOR模式(contd)object structural,效果responsibilities can be added/removed at run-timeavoids subclass explosionre
19、cursive nesting allows multiple responsibilities实现interface conformanceuse a lightweight,abstract base class for Decorator,24,2.5 支持多种视感标准,Want the application to be portable across diverse user interface libraries.Every user interface element will be a Glyph.Some will delegate to appropriate platfo
20、rm-specific operations.,25,Multiple Look&Feels,目标:support multiple look&feel standardsgeneric,Motif,Swing,PM,Macintosh,Windows,.extensible for future standards限制条件:dont recode existing widgets or clientsswitch look&feel without recompiling,26,解决方案:Abstract Object Creation,Instead ofScrollbar*sb=new
21、MotifScrollbar();useScrollbar*sb=factory-createScrollbar();where factory is an instance of MotifFactorythis begs the question of who created the factory!,27,Factory Interface,defines“manufacturing interface”subclasses produce specific productssubclass instance chosen at run-time,/This class is essen
22、tially a Java interfaceclass Factory public:Scrollbar*createScrollbar()=0;Menu*createMenu()=0;.;,28,Object Factories,Usual method:ScrollBar sb=new MotifScrollBar();Factory method:ScrollBar sb=guiFactory.createScrollBar();,29,Product Objects,The output of a factory is a product.,abstract,concrete,Abs
23、tract Factory,30,Building the Factory,If known at compile time(e.g.,Lexi v1.0 only Motif implemented).GUIFactory guiFactory=new MotifFactory();Set at startup(Lexi v2.0)String LandF=appProps.getProperty(LandF);GUIFactory guiFactory;if(LandF.equals(Motif)guiFactory=new MotifFactory();.Changeable by a
24、menu command(Lexi v3.0)re-initialize guiFactoryre-build the UI,Singleton,31,ABSTRACT FACTORY 模式 object creational,意图create families of related objects without specifying class names适用性when clients cannot anticipate groups of classes to instantiate,Structure,32,ABSTRACT FACTORY模式(contd)object creatio
25、nal,效果flexibility:removes type dependencies from clientsabstraction:hides products compositionhard to extend factory interface to create new products实现parameterization as a way of controlling interface sizeconfiguration with Prototypes,i.e.,determines who creates the factories,33,2.6 支持多种窗口系统,目标:mak
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- lexi 设计 案例 分析

链接地址:https://www.desk33.com/p-242020.html