1、1Chapter 7nRequirements Modeling:Flow and BehaviorSoftware Engineering:A Practitioners Approach,7/e by Roger S.Pressman2Requirements Modeling StrategiesnOne view of requirements modeling,called structured analysis,considers data and the processes that transform the data as separate entities.nData ob
2、jects are modeled in a way that defines their attributes and relationships.nProcesses that manipulate data objects are modeled in a manner that shows how they transform data as data objects flow through the system.nA second approach to analysis modeled,called object-oriented analysis,focuses on nthe
3、 definition of classesnthey collaborate with one another to effect customer requirements.3Flow-Oriented Modelingndata flow diagram(DFD)4Flow Modeling Notation5External EntityData must always originate somewhereand must always be sent to something6ProcessData must always be processed in some way to a
4、chieve system function7Data Flow8Data Stores9Data Flow Diagramming:Guidelinesnall icons must be labeled with meaningful namesnthe DFD evolves through a number of levelsnalways begin with the level 0ndo not represent procedural logicsourcedestination1A2B3Ccefdbab2.12.22.3de1F10Constructing a DFDInrev
5、iew user scenarios and/or the data model to isolate data objects and use a grammatical parse to determine“operations”ndetermine external entities(producers and consumers of data)ncreate a level 0 DFD11Level 0 DFD ExampleConstructing a DFDI12Constructing a DFDIInto determine next level transformsnEac
6、h sub-DFD provides a more detailed description n“balance”the flow to maintain data flow continuityneach Process is refined until it does just one thingnmost systems require between 3 and 7 levels for an adequate flow modelna single data flow item(arrow)may be expanded as levels increase13The Data Fl
7、ow Hierarchy教材管理系统的顶层DFD学生学生教材购销教材购销管理系统管理系统书书 库库保管员保管员购书单领书单缺书单进书通知Constructing DFDExample 教材管理系统可分为:销售子系统和采购子系统 销售子系统:由教师或学生提交购书单,经教材科发行人员审核是有效购书单后,开发票、登记并返给学生领书单,学生凭领书单领书。采购子系统:若是脱销教材,则登记缺书信息,并发缺书单给书库采购人员;一旦新书入库后,即发进书通知告知系统。15学生学生书书 库库保管员保管员第一层DFD图教材管理系统购书单领书单1销 售2采购进书通知F2:缺书登记表F1:教材存量表缺书单进书通知Con
8、structing DFDExample16Constructing DFDExample1.1 审 查有效性1.2 开发票有效 购书单1.3 开领书单发票1.4 登记缺书1.5 补售教材F2:缺书登记表学生学生无效书单领书单领书单F3:各班学生用书表F4:售书登记表 补售书单 暂缺书单采购子系统第二层DFD图销售子系统F1:教材存量表进书通知17Constructing DFDExample2.3 修改教材库存和待购量2.1 按 书 号 汇总缺书F2:缺书登记表销售子系统书库保管员F1:教材存量表进书通知第二层DFD图采购子系统2.2 按出版社 统计缺书F5:待购教材表F6:教材一览表进书通
9、知18DFDs:A Look Ahead19Process Specification(PSPEC)20Process Specification(PSPEC)21Control Specification(CSPEC)Represents“events”and the processes that manage events.An“event”is a Boolean binatorial spec22Control Specification-n一种介于自然语言和形式化语言之间的语言。n结构化语言的词汇表由n 英语命令动词n 数据词典中定义的名字n语言的正文用基本控制结构进行分割,加工中的
10、操作用自然语言短语来表示。n基本控制结构有三种:n简单陈述句结构;n重复结构:while_do 或 repeat_until 结构;n判定结构:if_then_else 或 case_of 结构。23if 发货单金额超过$500 then if 欠款超过60天 then 在偿还欠款前不予批准 else(欠款未超期)发批准书,发货单 else(发货单金额未超过$500)if 欠款超过60天 then 发批准书,发货单及赊欠报告 else(欠款未超期)发批准书,发货单24n判定表的构造方法:1)列出与一个具体过程有关的全部操作。2)列出该过程执行期间的所有条件或作出的判定3)找出每个可能的组合,将
11、各组特定的条件与特定操作相结合,并消去那些不可能发生的条件组合。4)指出在什么样的一组条件下将采取什么样的操作。如果算法中包含多重嵌套的条件选择时,用判定表能清晰地表达条件组合与动作之间的对应关系.Control Specification-25Control Specification-n判定树与判定表的逻辑处理相似,但比判定表的语义表达上更直观。n判定树中,每个枝节点(子树的根)对应于一个判定条件,而叶节点则对应于系统的一个可能的动作。n判定树中,从根到叶的每条路径上所有枝节点对应于一种条件组合取值下的特定动作。2627Behavioral Modeling&State Represent
12、ationnThe behavioral model indicates how software will respond to external events or stimuli.nIn the behavioral modeling,two different characterizations of states must be considered:nthe state of each class as the system performs its functionnthe state of the system as observed from the outside as t
13、he system performs its functionnThe state of a class takes on both passive and active characteristics.nA passive state is the current status of all of an objects attributes.nThe active state of an object indicates the current status of the object as it undergoes a continuing transformation.28The Sta
14、tes of a Systemnstatea set of observable circumstances that characterizes the behavior of a system at a given timenstate transitionthe movement from one state to anotherneventan occurrence that causes the system to exhibit some predictable form of behaviornactionprocess that occurs as a consequence
15、of making a transition29State Diagram Example-Elevator30Behavioral Modeling&Sequence Diagram nmake a list of the different states of a system(How does the system behave?)nindicate how the system makes a transition from one state to another(How does the system change state?)ndraw a sequence diagram31
16、The Interaction ModelnComposed of four elements:n use-casesn sequence diagramsn state diagrams n a user interface prototypenEach of these is an important UML notation2022-12-1732 时序图时序图 时序图时序图用于描述对象与对象之间动态的交互关系,着重用于描述对象与对象之间动态的交互关系,着重体现对象间消息传递的时间顺序。体现对象间消息传递的时间顺序。时序图有两个轴时序图有两个轴水平轴表示不同的类水平轴表示不同的类/对象,
17、垂直轴表示时间对象,垂直轴表示时间。时序图中的类时序图中的类/对象用一个带有垂直虚线的矩形框表示,并标有对象用一个带有垂直虚线的矩形框表示,并标有对象名对象名/类名。类名。垂直虚线是对象的垂直虚线是对象的生命线生命线,用于表示在某段时间内对象是存在,用于表示在某段时间内对象是存在的。的。对象间的通信通过在对象的生命线间画消息来表示,消息从上对象间的通信通过在对象的生命线间画消息来表示,消息从上到下,表明其发送的先后顺序。到下,表明其发送的先后顺序。消息是对象间的一次通信,传达了要执行动作的信息,它能触消息是对象间的一次通信,传达了要执行动作的信息,它能触发事件。消息可以是信号、操作、调用等,对
18、象接收到消息时,发事件。消息可以是信号、操作、调用等,对象接收到消息时,立即开始执行指定活动,即对象被激活了。立即开始执行指定活动,即对象被激活了。“激活激活”用对象生命线上的一个细长矩形框来表示。消息可以用对象生命线上的一个细长矩形框来表示。消息可以带序号(也可省略),还可带有条件表达式,表示该消息是否带序号(也可省略),还可带有条件表达式,表示该消息是否被发送。被发送。2022-12-1733时序图实例时序图实例:如图描述了某公司管理系统的脚本:如图描述了某公司管理系统的脚本“打印工资单打印工资单”。首先,。首先,“Print CilentPrint Cilent”发送消息发送消息prin
19、t(PayCheck,String)print(PayCheck,String)给给PrintServicePrintService,该,该对象发送消息给对象发送消息给PayCheckPrinterImagePayCheckPrinterImage以创建工资单,创建工资单的打印以创建工资单,创建工资单的打印图象时,需要取得雇员的姓名,图象时,需要取得雇员的姓名,IDID,工资数等,然后才建立打印图象,最,工资数等,然后才建立打印图象,最后发送后发送printprint(ImageImage)消息给)消息给PrinterPrinter,打印工资单的图象。,打印工资单的图象。激活生命线消息对象/类
20、34Sequence DiagramFi gure 18.5 Sequence di agram for use-case:sel ect SafeHom e com ponentsnew custom er:Room:Fl oorPl andescr i bes r oom*pl aces r oom i n fl oor pl an:Product Com ponentsel ects pr oduct com ponent*:Bi l l of M ateri al sadd to BoMFl oorPl an Reposi torysave fl oor pl an confi gur
21、 ati onsave bi l l of m ater i al sBoM Reposi tory35State DiagramFi gure 18.6 Parti al state di agram for n ne ew w c cu us st to om m e er r i nteracti onnew custom erVal i dati ng usersystem status=“i nput ready”di spl ay m sg =“enter useri d”di spl ay m sg=“enter psw d”entry/l og-i n requested do
22、:run user val i dati on exi t/set user access sw i tchsel ect“l og-i n”useri d val i datedpassw ord val i datedSel ecti ng user acti onsystem status=“l i nk ready”di spl ay:navi gati on choi ces”entry/val i dated user do:l i nk as requi red exi t/user acti on sel ected sel ect other functi onssel ec
23、t custom i zati on functi onal i tysel ect e-com m erce(purchase)functi onal i tyCustom i zi ngsystem status=“i nput ready”di spl ay:basi c i nstructi ons entry/val i dated user do:process user sel ecti on exi t/custom i zati on term i natedsel ect descri pti vecontentroom bei ng defi nedDefi ni ng
24、roomsystem status=“i nput ready”di spl ay:room def.w i ndow entry/room def.sel ected do:run room queri es do:store room vari abl es exi t/room com pl etedsel ect descri pti vecontentBui l di ng fl oor pl ansystem status=“i nput ready”di spl ay:fl oor pl an w i ndow entry/fl oor pl an sel ected do:i
25、nsert room i n pl ace do:store fl oor pl an vari abl es exi t/room i nserti on com pl etedsel ect descri pti vecontentsel ect enter room i n fl oor pl anSavi ng fl oor pl ansystem status=“i nput ready”di spl ay:storage i ndi cator entry/fl oor pl an save sel ected do:store fl oor pl an exi t/save co
26、m pl etedsel ect save fl oor pl anroom i nserti on com pl etednext sel ecti oncustom i zati on com pl eteal l room sdefi ned36Activity DiagramFi gure 18.7 Acti vi ty di agram for c co om m p pu ut te eP Pr ri ic ce e()o op pe er ra at ti io on ni ni ti al i ze total Costi nvokecal cShi ppi ngCostget
27、 pr i ce and quanti tycom ponents rem ai n on BoM Li sti nvoke deter m i neDi scountdi scount 0total Cost=total Cost-di scounttaxTotal=total Cost x taxr ateno com ponents rem ai n on BoM Li stl i neCost =pr i ce x quanti tyadd l i neCost to total Costpr i ceTotal=total Cost+taxTotal +shi ppi ngCostr etur ns:shi ppi ngCostr etur ns:di scount2022年12月17日37Flow-Oriented Modeling-Example2022年12月17日382022年12月17日392022年12月17日40