# 物件導向軟體工程 歷屆考古

# 期末考

以下內容沒有正確解答都是 FKT 的猜想,歡迎提供正確解答


# 108 Quiz-1

# Q1

  1. 一個好的 test case 是有高可能性讓你偵測到錯誤的因子 TRUE False
  2. 測試可以表示沒有錯誤發生,沒有錯誤存在 FALSE
  3. 測試的目的是證明錯誤存在 FALSE True

# Q2

這三個設計模型的維護模式是甚麼類型

  1. Abstract Factory: Corrective Maintenance AEP
  2. Builder: Adaptive Maintenance AEP
  3. Facade: Preventive Maintenance P

# Q3

  1. Class A 是 Class B 的 Function 參數型別
1
2
3
4
5
class ClassB{
void setup(ClassA classA){
//Do something
}
}
  1. Class A 是 Class B 的本地變數
1
2
3
class ClassB{
private ClassA classA;
}

# Q4

具有一系列連續字符串的非數字類型 S1-S2 他的 test cases 包含 S1,S2,null,"", 超長字串,請你定好 S1,S2 寫出它們字串長度的範例

“” length= 0

null length is nothing
String S1;
String S2;

# Q5

模組 A 的 的 DIT 中位數為 1 代表多數位於模組 A 的 Class 都是 DIT 1 代表相對簡單的繼承結構好維護,但在模組 A 的最大 DIT 出現的 DIT8 的 Class 這個 class 要特別注意建議將繼承拆分成更彈性的結構。
模組 B 的 DIT 中位數為 3 代表多數位於模組 B 的 Class 都是 DIT 3 代表在模組 B 的 Class 大多都是依賴於別的 class 設計的時候要特別注意父類的內容,且模組 B 的最大 DIT 出現的 DIT10 的 Class 較為難維護需要進行拆分結構。

# Q6

Appliance(WMC) 4
StoreDeparment(RFC) 3+1+4 = 8
StoreDeparment(DIT) 0

# Q7

Fan-In Fan-Out
CheckoutController 1 4
CheckoutGUI 0 1
DBMgr 1 2
Document 3 0
Loan 2 2
Patron 2 1
User 1 0
Total 10 10

# Q8

4 test cases

rules:

  1. if(stackReference ==null)
  2. if(this.Stack.size()==0 )
  3. if(this.Stack.size()==this.Stack.maxsize() )
  4. if(this.Stack.size()<=this.Stack.maxsize() )

# Q9

MTTF A = 360/18-3=17
MTTF B = 360/36-2=8
MTTR A = 3
MTTR B = 2
MTBF A = 20
MTBF B = 10
Availibility A: 17/20
Availibility B: 8/10

System A Availibility is more than System B

# Q10

Basic Path

  1. B 1 2 E
  2. B 1 2 3 4 9 10 2 E
  3. B 1 2 3 4 5 7 8 9 10 2 E
  4. B 1 2 3 4 5 6 9 10 2 E

CC1Number of closed regions plus 1 = 3+1=4
CC2Number of atomic binary predicate + 1 = 3+1=4
CC3Number of edges - Number of Nodes + 2 =12-10+2=4

# 109-2

# Q4

  1. Cloneable
  2. clone()
  3. CloneNotSupportedException
  4. super.clone();
    OutPut : “Car is Green Nano and its price is NTD.350000”
    OutPut : “Ford Yellow is Green Nano and its price is NTD.550000”

# Q5

淺複製:當我需要完全與原型大致相同但不需要相同的內部細節物件資訊時,當複製目標只有基礎型別屬性時與關係不重要時可以使用淺複製
深複製:當我需要完全複製一個與原型完全相同物件的時候,由於複製目標屬性中可能含有重要物件資訊與關聯我們需要使用深複製將物件屬性的物件內容一併複製過去當然也需要考慮該屬性物件是否可被複製。

# Q6

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
public interface DBImplInterface{
StateDiagram getDiagram(String name);
void saveDiagram(StateDiagram d);
void connectDB();
void disconnectDB();
}
public class RDBImpl implements DBImplInterface{
public StateDiagram getStateDiagram(String name){
connectDB();
StateDiagram statediagram;
//Get StateDiagram Operation
disconnectDB();
return stateDiagram
}
public void saveDiagram(StateDiagram d){
//save Diagram to RDB
}
public void connectDB(){
//Connect RDB
}
public void disconnectDB(){
//Disconnect RDB
}
}

public class LDAPImpl implements DBImplInterface{
public StateDiagram getStateDiagram(String name){
connectDB();
StateDiagram statediagram;
//Get StateDiagram Operation;
disconnectDB();
return stateDiagram
}
public void saveDiagram(StateDiagram d){
//save Diagram to LDAP
}
public void connectDB(){
//Connect LDAP
}
public void disconnectDB(){
//Disconnect LDAP
}
}
public class DBMgr{
DBImplInterface impl;
public DBMgr(DBImplIntrerface impl){
this.impl=impl;
}
public StateDiagram getDiagram(String name){
return impl.getDiagram(name);
}
public void saveDiagram(StateDiagram d){
impl.saveDiagram(d);
}

}
public class EditController{
DBImplInterface dbImplInterface = new RDBImpl;
DBMgr dbmgr = new DBMgr(dbImplInterface);
StateDiagram stateDiagram;
public void getDiagram(String name){
stateDiagram = dbmgr.getDiagram(name);
}
public void saveDiagram(StateDiagram stateDiagram){
dbmgr.save(stateDiagram);
}
}

# Q8

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
public interface Command{
void execute();
void undo();
}
public class CuttingCommand implements Command{
Stack<Memento> mementoStack;
Editor editor;
public CuttingCommand(Editor editor){
this.editor =editor;
this.mementoStack = new Stack();
}
public void execute(){
Memento m = this.editor.createMemento();
mementoStatck.push(m);
//Cutting Operation in Editor
}
public void undo(){
Memento m = mementoStack.pop();
editor.restoreMemento(m);
}
}
public class PastingCommand implments Command{
Stack<Memento> mementoStack ;
Editor editor;
public PastingCommand(Editor editor){
this.editor=editor;
this.mementoStack = new Stack<Memento>();
}
public void execute(){
Memento m = editor.createMemento();
mementoStack.push(m);
//Pasting Operation to Editor
}
public void undo(){
Memento m = mementoStack.pop();
editor.restoreMemento(m);
}
}
public class Memento{
String state;
public Memento(State state) {
this.state = state;
}
public String getState(){
return this.state;
}
}
public class Editor
String state;
public void setState(String state){
this.state=state;
}
public String getState(){
return this.state;
}
public Memento createMemento(){
Memento m = new Memento(state);
return m;
}
public void restoreMemento(Memento m){
this.state = m.getState();
}
}
public class CommandManager{
Stack<Command> pastCommandStack = new Stack();
Stack<Command> futureCommandStack = new Stack()
public execute(Command c){
pastCommandStack.push(c);
futureCommandStack.remove(c);
c.execute();
}
public void undo(){
Command c = pastCommandStack.pop();
futureCommandStack.push(c);
c.undo();
}
}
public class EditorController{
CommandManager cmdMgr = new CommandManager();;;
Editor editor;
public void doCutting(){
Command c = new CuttingCommand(editor);
cmdMgr.exexute(c);
}
public void doPasting(){
Command c = new PastingCommand(editor);
cmdMgr.execute(c);
}
public void undo(){
cmdMgr.undo();
}
}
更新於