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

期末考

以下內容沒有正確解答都是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
    }
    }
  2. 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();
}
}
更新於