6.OO迭代开发案例分析

1. OO迭代开发案例分析——MSG基金 问题描述: Martha Stockton Greengage在逝世后,留下20亿美元的财富 给慈善事业。她的遗嘱中还特别要求设立Martha Stockton Greengage基金(MSG),以帮助年轻夫妇购买他们自己的 房子。 为了减少操作费用,MSG的托管人正在研究开发一个 计算机系统。
2. MSG基金——贷款抵押条件 1) 结婚夫妇至少已经合法结婚一年,但未超过10年。 2) 双方都在职有薪水。特别是,必须提供双方在前一年全日工作 至少48个星期的证据。 3) 房子的价格必须比过去12月中那一地区公布的中等房价要低。 4) 以30年分期付款形式偿还的90%抵押款超过他们共同收入的 28%。 5) 基金会有足够的资金购买房子。 附件条件: 1)贷款人每月分期付款额包括本金和利息两部分。 2)贷款人签署一份法律文件(抵押贷款契约),声明如果每月的分 期付款无法支付,基金会可出售该房子,并用收益支付贷款余额。 3)基金会要求贷款人投保房子,以免房子发生烧毁等情况基金会可 以得到弥补。保险金一般是由基金会每年支付,但会要求贷款人每 月分期支付这部分保险金。
3. MSG基金——贷款偿还条件 如果申请被批准,则夫妇俩在今后的30年中,每星期 必须付给MSG的数额计算如下(每周): 1) 偿还资金是购买房价的1/1560(30年1560周)。 2) 应付利息是当前抵押余额4%的1/52。 3) 贷款保证金是每年财产税和房产所有人每年保险 费总和的1/52。 4) 每星期付给MSG的费用数额就是以上三项总和。 5) 如果4)项超过了家庭每星期收入的28%,则 MSG将以补助形式付余下的差额。
4. MSG基金——业务逻辑 MSG确定是否有资金批准一个抵押申请的过程如下: 1) 在每星期的一开始,计算总投资的预计年收入, 并除以52。 2) MSG的预计年操作费用除以52。 3) 计算本周预计的抵押偿还款总额。 4) 计算本周预计的补助总额。 5) 可用总金额是:1)-2)+3)-4)。 6) 如果房子成本不超过5),则MSG认为有购买房 子所需的资金。 7) 在周末,任何未用的资金都将有MSG投资顾问用 来投资。
5. MSG基金——面向对象分析与设计 OOA由3个活动组成,即功能建模、类建模、动态建模。 第1个是功能建模。用例提供整体功能的一般描述,场景 是用例的一个特定实例,就像对象是类的实例一样。可以 用用例和场景描述建立功能模型。 第2个是类建模。这一步的目的是抽取类,找出它们的属 性,并确定它们的相互关系。可从功能模型推导出初始类 ,然后不断补充完善,构造类的层次结构。 第3个是动态建模。为开发动态模型,应首先分析用例场 景。在MSG模型中,可能的情景与可能具有的操作功能相 对应。 OOD就是通过3个模型的迭代逐步实现用例的过程。
6. Case study: MSG Foundation the use-case diagram
7. Use Case Estimate Funds Available for Week
8. Use Case Produce a Report
9. The Initial Class Diagram: MSG Foundation  引入边界类、控制类及实体类的概念有助于分析和设计人员确定系统中的类。 边界类位于系统与外界的交界处,通过用例图可以确定需要的边界类,每个 Actor/Use Case对至少要一个边界类。 实体类用于保存要放进持久存储体的信息。通常每个实体类在数据库中有相应 的表。 控制类是控制其他类工作的类。每个用例通常有一个控制类,控制用例中的事 件顺序,控制类也可以在多个用例间共用。其。  Entity class:Account Class,Investment Class  Models long-lived information  Boundary class :Investments Report Class,Mortgages Report Class  Models the interaction between the product and the environment  A boundary class is generally associated with input or output  Control class :Estimate Funds for Week Class Models complex computations and algorithms
10. Noun Extraction: MSG Foundation  Stage 1: 描述信息系统文字段 Weekly reports are to be printed showing how much money is available for mortgages. In addition, lists of investments and mortgages must be printed on demand.  Stage 2: 识别文字段中的名词 Weekly reports are to be printed showing how much money is available for mortgages. In addition, lists of investments and mortgages must be printed on demand.
11. Noun Extraction: MSG Foundation (contd)  The nouns are report, money, mortgage, list, and investment Nouns report and list are not long lived, so they are unlikely to be entity classes (report will surely turn out to be a boundary class)  money is an abstract noun  This leaves two candidate entity classes  Mortgage Class and Investment Class
12. Second Iteration of the Initial Class Diagram  Operations performed on the two entity classes are likely to be very similar Insertions, deletions, and modifications All members of both entity classes have to be printed on demand  Mortgage Class and Investment Class should be subclasses of a superclass called Asset Class
13. Back to the Requirements Workflow
14. Second Iteration of Initial Class Diagram (contd)
15. The Initial Dynamic Model: MSG Foundation A statechart is constructed that reflects all the operations performed by or to the software product  The operations are determined from the scenarios 
16. Initial Dynamic Model: MSG Foundation (contd)  An MSG staff member selects an option by clicking on the menu  This graphical user interface (GUI) requires special software
17. Revising the Entity Classes: MSG Foundation     目前为止,已经建立了初始功能模型、初始类模型和初始动 态模型。现在要重新审查这些模型有没有问题…… 在初始动态模型的状态图中,有一个状态 Update Estimated Annual Operating Expenses 代表正在执 行操作 Update the estimated annual operating expenses, 似乎存在问题: Where is the value of the estimated annual operating expenses to be found? Another entity class is needed for storing the estimated annual operating expenses  MSG Application Class
18. Third Iteration of the Initial Class Diagram: MSG Foundation
19. Third Iteration of the Initial Class Diagram: MSG Foundation
20. Extracting the Boundary Classes: MSG Foundation  It is usually easy to extract boundary classes Each input screen, output screen, and printed report is generally modeled by a boundary class  One screen should be adequate for all four MSG Foundation use cases Estimate Funds Available for Week  Manage an Asset  Update Estimated Annual Operating Expenses  Produce a Report   Accordingly there is one initial boundary class User Interface Class
21. Extracting Boundary Classes: MSG Foundation (contd)  Three reports have to be printed The estimated funds for the week report The listing of all mortgages The listing of all investments  Each of these has to be modeled by a separate boundary class Estimated Funds Report Class Mortgages Report Class Investments Report Class
22. Extracting Boundary Classes: MSG (contd)  Here are the four initial boundary classes
23. Extracting the Control Classes: MSG Foundation  Each computation is usually modeled by a control class  The MSG Foundation case study has just one Estimate the funds available for the week  There is one initial control class
24. Class Extraction (contd)  Now return to see how to realize use case……
25. Estimate Funds Available for Week  Use Case (contd) Description of use case
26. Estimate Funds Available for Week Use Case (contd) •Class diagram (classes that enter into the use case)  The six classes that enter into this use case are:  User Interface Class  This class models the user interface  Estimate Funds for Week Class  This control class models the computation of the estimate of the funds that are available to fund mortgages during that week  Mortgage Class  This class models the estimated grants and payments for the week  Investment Class  This class models the estimated return on investments for the week  MSG Application Class  This class models the estimated return on investments for the week  Estimated Funds Report Class  This class models the printing of the report
27. Estimate Funds Available for Week  Use Case (contd) Scenario (one possible instance of the use case)
28. Estimate Funds Available for Week  Use Case (contd) Collaboration diagram (of the realization of the use case)
29. Estimate Funds Available for Week  Sequence diagram equivalent to the collaboration diagram (of the realization of the scenario of the use case) Use Case (contd)
30. Manage an Asset Use Case
31. Manage an Asset  Use Case (contd) Class diagram showing the classes that realize the use case
32. Manage an Asset  Use Case (contd) One scenario of the use case
33. Manage an Asset  Use Case (contd) Collaboration diagram of the realization of the scenario of the use case
34. Manage an Asset Use Case (contd) Sequence diagram equivalent to the collaboration diagram (of the realization of the scenario of the use case)
35. Manage an Asset  Use Case (contd) A different scenario of the use case
36. Manage an Asset  Use Case (contd) Collaboration diagram of the realization of the scenario of the use case
37. Manage an Asset  Use Case (contd) Sequence diagram equivalent to the collaboration diagram (of the realization of the scenario of the use case)
38. Manage an Asset Use Case (contd)  Two different scenarios of the same use case have been presented  The use case is the same The class diagram is therefore the same  However, the collaboration (and sequence) diagrams reflect the differences between the two scenarios
39. Manage an Asset  Use Case (contd) Boundary class User Interface Class appears in all the realizations  The same screen will be used for all commands of the information system  Revised menu
40. Manage an Asset  Use Case (contd) Corresponding textual interface
41. Update Annual Operating Expenses Use Case  Class diagram  Collaboration diagram of a realization of a scenario of the use case
42. Update Annual Operating Expenses Use Case (contd)  Equivalent sequence diagram Figure 12.49
43. Produce a Report  Use Case (contd) Description of use case Figure 12.51
44. Produce a Report Use Case (contd)  Class diagram  One scenario of the use case
45. Produce a Report  Collaboration diagram Mortgages (but not investments) are involved Use Case (contd)
46. Produce a Report  Sequence diagram Use Case (contd)
47. Produce a Report Use Case (contd)  Class diagram  Another scenario of the use case
48. Produce a Report Use Case (contd)
49. Produce a Report  Use Case (contd) Sequence diagram for second scenario
50. Combining the Realization Class Diagrams
51. Fourth Iteration of the Class Diagram
52. Conclusion from MSG case Perform the following three steps incrementally and iteratively Functional modeling  Present scenarios of all the use cases (a scenario is an instance of a use case) Class modeling    Determine the entity classes/ Boundary classes/ Control classes and their attributes Determine the interrelationships and interactions between the classes Present this information in the form of a class diagram Dynamic modeling   Determine the operations performed by or to each entity class Present this information in the form of a statechart