1 / 55

Design by Experience

Design by Experience. Software Engineering. Common Patterns in Static Design. We focus on the static relationships between classes and ignore their dynamic or time-dependent behavior. Collection Managers

raleigh
Download Presentation

Design by Experience

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Design by Experience Software Engineering

  2. Common Patterns in Static Design • We focus on the static relationships between classes and ignore their dynamic or time-dependent behavior. • Collection Managers • This is one of the most common patterns in the static object design。A manager class manages a collection of objects, including the creation and removal of those objects.

  3. 1.Collection Managers User Manager Users :User[*] <<constructor>>//构造程序 UserManger() <<get & query operations>>//提取询问 getUsers():User[*] getUser(usename:String): User getUserCount():Integer Contains(user:User):Boolean <<editing>> //编辑修改 addUser(usename:String) remouveUser(user:User) remouveAllUsers() Manages User Username:String User can only be created by UserManger

  4. 2.Containers The container only contains the objects and does not create them。 Collection Manager is responsible for creating an object to be added to the collection. Container accepts objects to be added into the collection. Thus the add operation has an object as input argument.。 Use Container as a servant class inside a collection manager class (delegation). Derive a collection manager class from Container (inheritance)

  5. Container Contains 容纳 Container Object:Object[*] <<constructor>>//构造程序 Container() <<get & query opeartions>>//提取询问 getAll():Object getCount():Integer Contains(object:Object):Boolean <<editing>>//编辑修改 Add(object:Object) remove(name:String) Remove(object:Object) removeAll() 1 * Object name:String Container never create object.

  6. 3.Self-Containing Classes, Hierarchies, and Networks • Object instance may contain other instance of the same class, leading to self-containment, • Such a recursive association yields a hierarchy or a tree。 • An object class may be associated with itself。

  7. (a)A self-containing Container Container * 1 Contains (容纳) Folder * 1 1 Contains 容纳 * File (b)A directory hierarchy with folders and files

  8. (a) A self-association with arbitary multiplicity on both ends San Francisco Washington Tokyo 1 Node Chicago * down Macao up LA HK (b) A postal network.

  9. Node//节点 Name:String upstreamNode:Node[*]//上游节点 downstreamNode:Node[*]//下游节点 <<constructor>>//构造程序 Node(name:String) <<get & query operations>>//提取和询问运算 getName():String//提取名字 getUpstreamNodeCount():Integer//提取上游节点数目 getDownstreamNodeCount():Integer//提取下游节点数目 getUpstreamNodes():Node[*]//提取所有上游节点数目 getDownstreamNodes():Node[*]//提取所有下游节点数目 getUpstreamNode(nodeName:String):Node//提取上游节点 getDownstreamNode(nodeName:String):Node//提取下游节点 isUpstreamTo(node:Node):Boolean//是否在输入节点的上游 Detailed design for the Node network

  10. continuation <<editing>>//编辑修改 addUpstreamNode(node:Node)//增加上游节点 addDownstreamNode(node:Node)//增加下游节点 removeUpstreamNode(node:Node)//去除上游节点 removeDownstreamNode(node:Node)//去除下游节点 removeUpstreamNode(nodeName:String)//去除上游节点 removeDownstreamNode(nodeName:String)//去除下游节点 removeAllNode()//去除所有节点

  11. 4 Relationship Loops • When two classes are related by both aggregation and inheritance。 • Relationship Loop – Common with rich domain • How to identify? Seek out multiple aggregate relationships from the same base. Determine appropriate type of relationship. Backward or Forward containment. Node.

  12. Two-tier relationship loops A A * B B * (A) backward containment (B) forward containment

  13. The FolderItem-Folder relationship loop. FolderItem Folder FolderItem * * 1 1 * Folder 1 FolderItem Folder Relationship fission breaks the loop into two parts.

  14. A relationship loop with leaf node classes Contains (容纳) 1..* Item 1 Group Circle Square Relationship loops can be generalized to include leaf node classes, which are end objects in a recursive aggregate.

  15. Relationship Fission Relationship fission is the process of decomposing relationship loops into aggregation and inheritance relationships。 Steps: Start from the top aggregation classes, draw the aggregation between super and sub classes。 Substitute superclasses with sunclasses one by one。 Finnally, the taxonomic relationship is a simple copy of the inheritance tree。

  16. Inheritance of Relationship Loops Floder FloderItem * 1 Contains (容纳) Secured Floder Secured FloderItem Inheritance from a backward-containment relationship loop

  17. Double Loops Contains (容纳) 1 Component Contains (容纳) * * Part Attribute 1 A double relationship loop with both forward and backward containment.

  18. Three Tiers Relationship Loops A * C * B * * A B C A three-tier relationship loop with backward containment from subclass to superclass.

  19. Binary Association Loops Binary association classes often appear along with other object patterns. In addition, there may be more than one association between two classes。 Supplier * Trade * Buyer Examples of association class shown in UML notation.

  20. An implemenation of ageneric binary association class. 方法是把供应者和买家对象直接放到交易中,作为它的属性。 注意:图中任用可变阵列trades来装载多个交易。 Implementing BFC Supplier Company_name:String Address:String Trades:Trade[*] Trade porduct:String qunity:Integer total_price:Double upplier:Supplier buyer:Buyer 1 * 1 Buyer name:String trade:Trade[*] *

  21. Recursive Association Class 关联类可用于带有自容或递归的关联,成为递归关联类。 subPart (下层零件) subPart (下层零件) Part Part * 1 parent (上层零件) * 1 parent (上层零件) * Property Property * A binary association class Property for the self-containing Part class.

  22. The Handler-Body Pattern (bridge) The essence of the handle-body pattern is the aggregation of multiple Property or Role objects。 has Person Role 1 * * * User Buyer Supplier trade A Role class is used as a servant class to the original superclass。If we consider that the aggregate is in effect defined by its collection of Property or Role objects, then this leads to dynamic schema.

  23. Dynamic Schema By dynamic schema, we mean an object design that can classify object instances on the fly, with modifying the design or recompiling the source codes. * 1 Category Part belongs to 1 1 * * * 1 Atrribute Property belons to String Atrribute Float Atrribute The dynamic schema pattern

  24. Calalog Schema Manager 1 1 * * subCategory * 1 subpart Part Category * belongto * 1 1 1 1 * * 1 Atrribute Property * belongto A simplified Product Data Management System based on the dynamic schema pattern。虚线框内是动态模式。Part和Categor类各自形成层次状结构,各有部属零件。目录Catalog负责管理零件,模式管理器SchemaManger则管理多个类型的模式。

  25. Shared Object Pools (flyweight) An object design using the shared object pool pattern. We note that this pattern is in essence the same as the flyweight pattern. The shared objects are the flyweights and the collection manager is the flyweight factory, which create flyweights. Catalog 1 * uses Tool Part * * shared objects Context

  26. Object Model for XML 标记语言(markup language),是指怎样在文件和文字数据中加插符号和标记的一种标种机制。 XML(Extensible Markup Language),是允许使用者自行定义标记。从而带有扩充能力的标记语言。 xml 衍生自一种更为普遍的标记语言,称为“标准广义标记语言。由国际标准组织认可,可让用者定义文件的类型,标记和结构。其虽广泛,但其复杂。于是在“国际网”协会的协助下,发展了xml。目的有几个:一是简化文件标记,二是可以让带有xml标记的文件在因特网上直接使用,三是使xml文件更为人懂。

  27. XML Basics xml标记法则有如下五项: (1) xml文件以说明语句 <?xml…?>起始。 (2) 文件中有三种标签(tag):书(book),章(chapter),和节(section)。 元素的开始和结尾由起始标签(start tag)和终结标签(end tag)界定。 (3) 一个元素可以含有零或多个元素和文字串,要按一定的顺序排列。而且,元素之间要有正确的嵌套。 (4)一个元素的起始标签中,可以附上一组属性。 (5)如果在属性的植或文字数据中有个别的文字xml标记符号,则用下面的特殊符号代替它们。 作为值或数据出现的符号: ‘ “ < > & 换成对应的xml特殊符号:&apos; &quot; &lt; &gt; &amp

  28. XML Object Models Connect * {有序} Text text:String Element name:String 1 1 xml合式文件的对象模型 * Attr name:String value:String Note that Connect is an abstract class(as indicated by italicized name).

  29. To convert an objet model into an XML object model, one may employ the following procedure: • Decompose relationship loops into aggregation and inheritance relationship. • 2. Tag the classes with UML sterotypes << Element>> and <<Attr>> . For classes that may contain other objects or itself, use <<Element>>. For classes containing only (name, value) pairs, or attributes of <<Element>> classes, use <<Attr>> • Object stereotype Class name Attribute • <<Element>> Maps to an element nameEach attribute maps to an XML attribute • <<Attr>> IgnoreThe (name, value)pair become an attribute of the parent.

  30. The XML object model for the Catalog hierarchy <<Element>> Catalog name:String 1 * <<Element>> Part name:String * 1 1 * <<Atrr>> Attribute name:String value:String

  31. Using the rules, we get the sample XML document <?xml version=“1.0”encoding=“GB2312”standalone=“yes”?> <Catalog name=“electronics”> <Part name=“resistorList”> <Part name=“resistorList” partNumber=“123” resistance=“5.6 Ohm”power=“ 0.1”W/> <Part name=“resistorList” partNumber=“323” resistance=“1.2 Ohm”power=“ 0.2”W/> </Part> <Part name=“resistorList”>

  32. <Part name=“capacitorList” partNumber=“13” capacitance=“1.6mF”voltage=“ 20”V/> <Part name=“capacitorList” partNumber=“14” capacitance=“0.1mF”voltage=“ 5”V/> <Part name=“capacitorList” partNumber=“15” capacitance=“200mF”voltage=“ 10”V/> </Part> </Catalog>

  33. The Strengths and Weakness of XML Xml can handle many cases of structured data, it is by no means a full object –oriented language. In particular, XML: (1)xmldoes not provide genuine links between objects。 (2)xmlcannot handle multiple parent cases (multiplicity more than one on the aggregate side)。 (3)xml does not provide object-oriented features like inheritance and methods。

  34. Case Study: ATM Systems-Part 1 Project Description 这个开发项目,目的是建立一个柜员机系统软件(ATM)。整个ATM系统包括自动柜员机、中央服务器、自动柜员机系统元件、及有关的界面元件。 ATM系统元件的工作,是处理系统中自动柜员机和银行电脑之间的事项。如查询、提款等。 对ATM 系统软件的要求有多项,现排列如下: (1)对所有使用ATM系统的事项,都要留有记录,且能每天作报告。 (2)系统要有安全措施。

  35. (3)一个户口必须能够同时从多处接入作者查询或其他帐务。(3)一个户口必须能够同时从多处接入作者查询或其他帐务。 (4)必须能兼顾未来的扩展,如增加出纳点,因特网客户机等。 在设计系统时,必须把以下限制考虑在内: (1)ATM系统由银行协会拥有。 (2)ATM系统软件在中央服务器里运行。 (3)各银行自己发行提款机,并保管有关资料。一家银行发行的卡,头六个数字相同。 (4)所有自动柜员机有同样的程序界面。 (5)每一家银行的电脑有其程序界面,不一定与其他银行的相同。

  36. State Analysis and Design 模型对象的分析和设计有两方面:静态和动态。静态分析包括认出对象类及其静态关系。动态分析则集中于对象间的相互作用和对外界面。以上列出的四条要求中,(1)和(4)直接影响着系统的静态设计。(2)和(3)则和动态设计更相关。这里要注意,通常涉及系统安全的,都和静态设计有关。但现在因为用户密码存放在银行电脑,ATM系统软件只需作中继站,把有关数据传到银行电脑,故(2)对静态设计影响不大。 事项是指持提款卡的顾客,在柜员机所作事情的记录。所以,它是提款卡与柜员机之间的一个连接。也就是说,可以把事项看成二元关联类,并作为设计的核心对象。

  37. * * 事项(Transaction)是ATM系统软件的核心设计,是一个二元关联类,把提款卡(Card)和自动柜员机(ATM)联系起来。

  38. 另加一个ATM管理器(ATMManager)管理所有银行资料和事项。银行资料则管理自己银行的提款卡(Card)。下图是以上核心设计的扩充。另加一个ATM管理器(ATMManager)管理所有银行资料和事项。银行资料则管理自己银行的提款卡(Card)。下图是以上核心设计的扩充。 * 1 1 manages 1 * manages * * * ATM系统软件的局部设计图

  39. 以照顾未来需要,如增加出纳点和因特网用户机等。可把ATM类换成抽象类“经济”(Agent),并由后者衍生三个子类,得到ATM系统软件设计总图。注意,图中的经济类也由ATM管理器管理。注意,图中“Agent”是一个抽象类。以照顾未来需要,如增加出纳点和因特网用户机等。可把ATM类换成抽象类“经济”(Agent),并由后者衍生三个子类,得到ATM系统软件设计总图。注意,图中的经济类也由ATM管理器管理。注意,图中“Agent”是一个抽象类。 ATM Manager BankInfo * 1 1 managers 1 managers ATM * Card * Cashier * Transttraction * Agent Internet *

  40. Case Study: Shared Whiteboard – Part 1 目的是建立一个公用讨论板,让联网的用户能一起讨论,并作图姓和文字标记。在本开发项目的第一阶段,先建立一个独立的“白板”;第二阶段再把这些“白板”连接起来,成为公用讨论板。 11.1 Introduction “白板”是一个图形工具,他有一个背景图形,用户可以作图形或文字标记,覆盖在图像之上。“白板”对背景图象没有编辑能力,当能改变覆盖在上面的图形或文字,并存到一定格式的文件中。 公用讨论板是白板的扩充板,能让联网的用户对背景图象作讨论。

  41. Functional Requirements (1)公用讨论板可显示一背景图象,图像从GIF或JPEG格式的图象文件读进,而且不可用讨论板改变(第一阶段)。 (2)公用讨论板可让用户作文字或图形标记,后者包括:之线、圆、椭圆和矩形。 (3)利用公用讨论板,用户可增减、选择、或移动以上的文字和图形标记,也可改变标记的形式,如颜色等。 (4)公用讨论板可把文字和图形标记存储到CGM(computer graphics metafile)格式的文件中,并可读回该类文件,然后显示内含的标记。

  42. (5)公用讨论板可形成一个组合,共看同一背景图象。用户可按一定秩序加上标记,并把标记播放到整个小组,让所有人都看到(第二阶段)。(5)公用讨论板可形成一个组合,共看同一背景图象。用户可按一定秩序加上标记,并把标记播放到整个小组,让所有人都看到(第二阶段)。 (6)用户若要加入现行的合作小组,直要连到组里的任一个共用讨论板,即可。用户也可随意离开小组,而不影响其他人(第二阶段)。 (7)将来标记的类型可能会增加。 11.3 User Interface 用户界面设计应依循“视窗”的标准: •可利用鼠标来产生、改变和清除标记。 •给所有的操作提供下拉菜单。 •给常用的操作提供快速按钮。

  43. System Attributes (1)公用讨论板要求不依赖电脑平台,可在不同的操作系统上使用。 (2)公用讨论板将在一个安全内部实施中使用,故无需另加安全措施。 File Edit Draw Help (菜单横条) (按钮屏面) 2 red Courier Bold 16 DrawCanvas 第一阶段白板的版面设计示意图

  44. 根据以上版面设计,很容易得到以下图的对象模型。主框架有三个类复合而成:MainMenuBar、MainButton和DrawCanvas。根据以上版面设计,很容易得到以下图的对象模型。主框架有三个类复合而成:MainMenuBar、MainButton和DrawCanvas。 1 1 <<Frame>> Main Main MenuBar ImagePort 1 1 1 1 1 1 * ImageButton 1 Main ButtonPanel <<Canvas>> DrawCanvas 1 LineChoose 1 1 * ColorChoose Glyph 1 FontChoose 第一阶段白板的对象模型

  45. 下图是绘画布类的详细设计。绘画布类的构造程序以一个背景图象作输入量。显示运算包括绘画,更新和清屏。 DrawCanvas image:Image glyphs:Container theGlyph:Glyph currentGlyphType:Integer <<constructor>> DrawCanvas(image:Image) <<disply & editing>> Paint(gr:Graphics)/refresh()/clera() Copy()/cut()/paste()/erase() Shift(dx:Short, dy:Short) processMouseEvent(e:MouseEvent) <<exernal linkage>> getGlyphsTo(imgPort:ImagePort)

  46. sendGlyphsTo(imgPort:ImagePort) sendGlyphsFrom(file:String) getGlyphsTo(file:String) getImageFrom(imgPort:ImagePort) sendImageTo(imgPort:ImagePort) 接下讲图符类,属性确定图符种类。 Glyph type:integer X,Y:Short[*] line Width :Integer color:Integer text:String key:Integer <<constructor>> Glyph(type:Integer,X:Short,Y:Short,…)

  47. Clone():Object <<display & editing>> draw(gr:graphics) drawBound(gr:Graphics) intersect(x:Short,y:Short):Boolean shift(dx:Short,dy:Short) <<external linkage>> toCGM(cgm Tool:CGMTool) 图符类的详细设计图 图符类的构造程序意图符的所有基本属性为输入变量,其他运算在下表中列出。

  48. 图符类的运算 已经构造了图符,则由绘画布中的绘画运算画出,下面是有关得伪码:

  49. Void paint (Graphics gr){ 对图符容器中的每一个图符,都可调用绘画运算。 如果“当前图符”有值,则调用画框运算;} 最后,图符和CGM数据之间的转换,由一组公用程序处理。如图2-38所示,CGM类含有服务类CGMTool,后者一组产生CGM字节数据的运算。 1 CGM CGMTool 1 1 * 共用讨论板中CGM共用程序的工具对象 Glyph

  50. CGM类含有一组图符,另有一字节阵列,作为缓冲存储器。CGM类借用CGM 工具,把图符转换成CGM数据,也可把CGM转换成图符。CGM的细详细设计见图。 CGM cgmTool:CGMTool Glyphs:Container Buffer:Byte[*] <<constructor>> CGM CGM(glyph:Glyph[*]) CGM(buffer:Byte[*]) <<editing>> add(glyphs:Glyph[*] add(glyph:Glyph) <<external I/O>> write(file:File) read(file:File)

More Related