Presentation is loading. Please wait.

Presentation is loading. Please wait.

徐迎晓 xuyingxiao@126.com 复旦大学软件学院 实现模型 徐迎晓 xuyingxiao@126.com 复旦大学软件学院.

Similar presentations


Presentation on theme: "徐迎晓 xuyingxiao@126.com 复旦大学软件学院 实现模型 徐迎晓 xuyingxiao@126.com 复旦大学软件学院."— Presentation transcript:

1 徐迎晓 xuyingxiao@126.com 复旦大学软件学院
实现模型 徐迎晓 复旦大学软件学院

2 实现模型 输入:设计过程的制品(交互图,设计类图) 可边设计边编程 对2周的迭代,考虑靠近迭代开始的半天做可视化建模设计工作,再进入编程
设计得到的是不完整的结果,编程和测试时会有大量修改,并发现和解决大量细节问题

3 实现模型 MAPPING DESIGNS TO CODE Testing & Refactoring Component Diagram
Deployment Diagram

4 MAPPING DESIGNS TO CODE
Defining a Class with Methods and Simple Attributes

5

6

7

8 Creating Methods from Interaction Diagrams

9

10 实现的顺序

11

12 Test-First Programming
编写代码之前编写单元测试代码 节奏:编写一点测试代码(SaleTest),再编写一点产品代码(Sale),通过测试后,再编写一点测试代码,…

13 优点 若放到后面写,程序员的天性是不写单元测试代码
心理学上,先编产品代码,再非正式测试,再事后增加单元测试,则感觉不是很满意。先写测试代码,再编写产品代码并改进之以通过测试,可增加程序员成就感。 先编写测试代码,可澄清类中的操作确切含义 成百上千的单元测试提供了有意义的验证 增强修改代码时的信心

14 实现模型 MAPPING DESIGNS TO CODE Testing & Refactoring Component Diagram
Deployment Diagram

15 Accepted best practices in OO
Testing & Refactoring Accepted best practices in OO Write unit tests prior to coding Refactor code continuously

16 Testing & Refactoring Unit testing Tests get written (not postponed)
Programmers get better at writing tests Deeper understanding prior to coding Reusable automated verification Rerun all unit tests after every code change Change code w/o excessive debugging JUnit is the testing framework for Java W/O WITHOUT

17 Testing & Refactoring Unit testing steps
Create object to be tested Do something to it (invoke some method) Check if results are correct Write tests for 1 method at a time

18 Fig. 21.1 JUnit in Eclipse IDE

19 Testing & Refactoring Refactoring
Structured, disciplined method of rewriting/restructuring code w/o changing its behavior Refactor in small steps ‘Refactoring: Improving the Design of Existing Code’, by Fowler Eclipse provides built-in support

20 Why refactor? Improve Design!
Testing & Refactoring Why refactor? Improve Design! Remove duplicate code Improve clarity Shorten methods Remove hard-coded constants Move methods to another class See Fowler’s book for more! Inseparable from iterative OOAD

21 Refactoring indications
Testing & Refactoring Refactoring indications Duplicate code Big methods Class with lots of instance variables Very similar subclasses Few/no interfaces High coupling Lots more…

22 Fig

23

24 Fig. 21.2 Extract Method refactoring example private Piece piece;
public class Player { private Piece piece; private Board board; private Die[] dice; // … public void takeTurn() // roll dice int rollTotal = 0; for (int i = 0; i < dice.length; i++) dice[i].roll(); rollTotal += dice[i].getFaceValue(); } Square newLoc = board.getSquare(piece.getLocation(), rollTotal); piece.setLocation(newLoc); } // end of class Move dice rolling loop to another method! Extract Method refactoring example

25 Fig. 21.3 After refactoring, this method now rolls the dice
public class Player { private Piece piece; private Board board; private Die[] dice; // … public void takeTurn() // the refactored helper method int rollTotal = rollDice(); Square newLoc = board.getSquare(piece.getLocation(), rollTotal); piece.setLocation(newLoc); } private int rollDice() int rollTotal = 0; for (int i = 0; i < dice.length; i++) dice[i].roll(); rollTotal += dice[i].getFaceValue(); return rollTotal; } // end of class After refactoring, this method now rolls the dice

26 Fig. 21.4 Introduce Explaining Variable Refactoring
// good method name, but the logic of the body is not clear boolean isLeapYear( int year ) { return ( ( ( year % 400 ) == 0 ) || ( ( ( year % 4 ) == 0 ) && ( ( year % 100 ) != 0 ) ) ); } Introduce Explaining Variable Refactoring What do all the numbers really represent? What is being returned?

27 Fig. 21.5 // that’s better! boolean isLeapYear( int year ) { boolean isFourthYear = ( ( year % 4 ) == 0 ); boolean isHundrethYear = ( ( year % 100 ) == 0); boolean is4HundrethYear = ( ( year % 400 ) == 0); return ( is4HundrethYear || ( isFourthYear && ! isHundrethYear ) ); } Method refactored by introducing variables that explain what the numbers mean It is now clear under what logical conditions a leap year occurs!

28 Fig. 21.6 Refactoring support in eclipse

29 Fig. 21.7 takeTurn method after refactoring

30

31

32

33

34

35

36

37 实现模型 MAPPING DESIGNS TO CODE Testing & Refactoring Component Diagram
Deployment Diagram

38 构件图

39 Component Component. 为存在于节点上的物理事物建模(可执行体、库、表、文件、文档)
构件名称:简单名,路径名,可用标记值或分隔栏修饰

40 构件实现类

41 构件和接口

42 构件种类 实施构件deployment components. 工作产品构件work product components. 执行构件
构成可执行系统必要和充分的构件 如DLL,EXE。 工作产品构件work product components. 开发过程中的源代码、数据文件等,用来生成可执行系统 执行构件 正在执行的系统的产生的结果,如DLL实例化形成的COM+对象

43 构件标准元素 标准元素 可执行体executable:能在节点上执行的构件 库library:动态或静态对象库 表table:数据库表
文件file:含源代码和数据的文档 文档document:文档

44 构件-可执行体和库

45 构件-表,文件和文档

46 构件-API

47 构件——源代码

48 构件图——源代码

49 构件图——可执行体的发布

50 构件图——可执行体的发布2

51 构件图——物理数据库

52 实现模型 MAPPING DESIGNS TO CODE Testing & Refactoring Component Diagram
Deployment Diagram

53 Deployment Diagram

54 实施——节点 节点:存在于运行时,并代表一项计算资源的物理元素,一般至少拥有一些内容,通常具有处理能力

55 实施——节点2 通常只显示名称,可用标记值或附加栏修饰

56 实施——节点和构件 节点是执行构件,构件是被节点执行的事物 节点隐含依赖构件

57 实施——节点属性 节点可以有属性(如处理器速度,内存容量等) 可以有操作 如turnOn, turnOff suspend

58 实施——节点的组织 包,依赖,泛化,关联,实现

59 实施——处理器和设备

60 实施——构件分布

61 实施图 内容 节点 依赖和关联 各种图中都有的注解和约束 可包括包和子系统 可有构件

62 实施图——嵌入式系统

63 实施图——客户/服务器系统

64 实施图——全分布式系统

65 穿插Rose演示 绘制构件图和实施图 ROSE正向工程和逆向工程


Download ppt "徐迎晓 xuyingxiao@126.com 复旦大学软件学院 实现模型 徐迎晓 xuyingxiao@126.com 复旦大学软件学院."

Similar presentations


Ads by Google