lexi设计案例分析.pptx
《lexi设计案例分析.pptx》由会员分享,可在线阅读,更多相关《lexi设计案例分析.pptx(75页珍藏版)》请在淘文阁 - 分享文档赚钱的网站上搜索。
1、lexi设计设计案例分析案例分析2.1 设计问题Lexi设计的7个问题1 文档结构:对文档内部表示的选择几乎影响Lexi设计的每个方面。2 格式化3 修饰用户界面4 支持多种视感标准5 支持多种窗口系统6 用户操作7 拼写检查上述每个问题都有一组相关联的目标集合和限制条件集合。2.2 文档结构目标保持文档的物理结构。即将文本和图形安排到行、列和表等。可视化生成和显示文档。根据显示位置来映射文档内部表示的元素。限制条件应该一致地对待文本和图形。应该一致地对待简单元素和复合元素。但文本分析依赖于被分析对象的类型。解决方案:递归组合递归组合:Building more complex element
2、s out of simpler ones.行列(段落)页(P24 第2段第2行)第5行第2列的第10个元素 The tenth element in line five of column two,隐含:Each object type needs a corresponding classAll must have compatible interfaces(inheritance)图2 包含正文和图形的递归组合图3 递归组合的对象结构Glyph(图元类)Base class for composable graphical objectsAn Abstract class for all
3、 objects that can appear in a document.Both primitive and composed.void insert(Glyph)void remove(Glyph)Glyph child(int)Glyph parent()管理子图元的接口boolean intersects(Coord,Coord)判断一个指定的点是否与图元相交void draw(Window*)Void Bounds(Rect)在窗口上表示自己返回图元占用的矩形面积操作任务基本接口:子类:Character,Image,Space,Row,Column 图元类层次Note the
4、inherent recursion in this hierarchywi.e.,a Row is a Glyph&a Row also has Glyphs!Glyph Interface and responsibilitiesGlyphs know how to draw themselvesGlyphs know what space they occupyGlyphs know their children and parentspublic abstract class Glyph /appearance public abstract void draw(Window w);p
5、ublic 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();COMPOSITE 模式 object structural意图treat individual objec
6、ts&multiple,recursively-composed objects uniformly适用objects must be composed recursively,and no distinction between individual&composed elements,and objects in structure can be treated uniformlyStructureCOMPOSITE 模式(contd)object structural效果+uniformity:treat components the same regardless of complex
7、ity+extensibility: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 deleting children由Composite负责删除其子节点
8、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 algorithm without modifying Glyphscan add Glyphs
9、without modifying the formatting algorithm.Want to make it dynamically changeable.Composition&CompositorCompositorbase class abstracts linebreaking algorithmsubclasses for specialized algorithms,e.g.,SimpleCompositor,TeXCompositor接口接口格式化内容:格式化内容:void SetComposition(Composition*)格式化:格式化:virtual void
10、Compose()()Compositioncomposite glyphsupplied a compositor&leaf glyphscreates row-column structure as directed by compositorComposition&Compositor一个未格式化的Composition对象只包含组成文档基本内容的可见图元,它并不包含像行和列这样决定文档物理结构的图元。Composite对象只在刚被创建并以待格式化的图元进行初始化后的状态当Composition对象需要格式化时,调用它的Compositor的Compose操作。Compositor依次遍
11、历Composition的各个图元,根据分行算法插入新的行和列图元。Generated in accordance with compositor strategies&do not affect contents of leaf glyphsCompositor&CompositionCompositor class will encapsulate a formatting algorithm.Compositor&Composition分行算法封装能增加新的Compositor子类而不触及Glyph类可在运行时刻改变分行算法在Composition接口中增加一个SetCompositor
12、操作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 algorithms can be encapsulated,and one interface covers all encapsula
13、tions 结构STRATEGY模式(contd)object behavioral效果+greater flexibility,reuse+can change algorithms dynamicallystrategy creation&communication overheadinflexible Strategy interfacesemantic incompatibility of multiple strategies used together实现exchanging information between a Strategy&its contextstatic stra
14、tegy selection via templates2.4 修饰用户界面Wish to add visible borders and scroll-bars around pages.Inheritance is one way to do it.leads to class proliferationBorderedComposition,ScrollableComposition,BorderedScrollableCompositioninflexible at run-timeWill have classesBorderScrollerThey will be Glyphsth
15、ey are visibleclients shouldnt care if a page has a border or notThey will be composed.but in what order?2.4 修饰用户界面目标:add a frame around text compositionadd scrolling capability限制条件:embellishments should be reusable without subclassing,i.e.,so they can be added dynamically at runtimeshould go unnoti
16、ced by clients解决方案:“Transparent”Enclosure(透明围栏)Monoglyph:起修饰作用的图元的抽象类:起修饰作用的图元的抽象类base class for glyphs having one childoperations on MonoGlyph pass through to childMonoGlyph subclasses:Frame:adds a border of specified widthScroller:scrolls/clips child,adds scrollbarsMonoGlyphBorder calls MonoGlyph.
17、draw();drawBorder();Transparent Enclosuresingle-child compositioncompatible interfacesEnclosure will delegate operations to single child,but canadd stateaugment by doing work before or after delegating to the child.DECORATOR 模式 object structural意图augment One object with new responsibilities适用性when e
18、xtension by subclassing is impracticalfor responsibilities that can be withdrawnStructureDECORATOR模式(contd)object structural效果+responsibilities can be added/removed at run-time+avoids subclass explosion+recursive nesting allows multiple responsibilities实现interface conformanceuse a lightweight,abstra
19、ct base class for Decorator2.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 platform-specific operations.Multiple Look&Feels目标:support multiple look&feel standardsgeneric,Motif,Swing
20、,PM,Macintosh,Windows,.extensible for future standards限制条件:dont recode existing widgets or clientsswitch look&feel without recompiling解决方案:Abstract Object CreationInstead ofScrollbar*sb=new MotifScrollbar();useScrollbar*sb=factory-createScrollbar();where factory is an instance of MotifFactorythis be
21、gs the question of who created the factory!Factory Interfacedefines“manufacturing interface”subclasses produce specific productssubclass instance chosen at run-time/This class is essentially a Java interfaceclass Factory public:Scrollbar*createScrollbar()=0;Menu*createMenu()=0;.;Object FactoriesUsua
22、l method:ScrollBar sb=new MotifScrollBar();Factory method:ScrollBar sb=guiFactory.createScrollBar();Product ObjectsThe output of a factory is a product.abstractconcreteBuilding the FactoryIf known at compile time(e.g.,Lexi v1.0 only Motif implemented).GUIFactory guiFactory=new MotifFactory();Set at
23、startup(Lexi v2.0)String LandF=appProps.getProperty(LandF);GUIFactory guiFactory;if(LandF.equals(Motif)guiFactory=new MotifFactory();.Changeable by a menu command(Lexi v3.0)re-initialize guiFactoryre-build the UIABSTRACT FACTORY 模式 object creational意图create families of related objects without specif
24、ying class names适用性when clients cannot anticipate groups of classes to instantiateStructureABSTRACT FACTORY模式(contd)object creational效果+flexibility:removes type dependencies from clients+abstraction:hides products compositionhard to extend factory interface to create new products实现parameterization a
25、s a way of controlling interface sizeconfiguration with Prototypes,i.e.,determines who creates the factories2.6 支持多种窗口系统目标:make composition appear in a windowsupport multiple window systems限制条件:minimize window system dependencies in application&framework code2.6 支持多种窗口系统是否可以用 Abstract Factory模式?Each
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- lexi 设计 案例 分析
限制150内