1 Abstract Data Types (11 Points) : Not Allowed Not Allowed
1 Abstract Data Types (11 Points) : Not Allowed Not Allowed
1 Abstract Data Types (11 Points) : Not Allowed Not Allowed
5
3
t
4 3
t = make (3) left (t)
root (t) = 3
has children (t) = False 1 2
left (t) −−> not allowed
right (t) −−> not allowed right (t)
t
Example 3
t = merge (merge (make (6), make (7), 8), right (merge (make (4), merge (make (1), make (2), 3), 5)) , 9)
8 3
6 7 1 2
root (t) = 9
right (t)
has children (t) = True
left (t)
left (t) −−> see Figure
right (t) −−> see Figure
t root ( left ( right (t))) = 1
1
ETHZ D-INFK
Prof. Dr. B. Meyer Software Architecture – Exam
TYPES
TREE
FUNCTIONS
• make: INTEGER → TREE
• merge: TREE × TREE × INTEGER → TREE
PRECONDITIONS
• P1: left (t) require has children (t)
• P2: right (t) require has children (t)
AXIOMS
• A1: root (make (i)) = i
2
Legi-Nr.:...............................................
• Name one architectural pattern that you will use (not design pattern).
• Draw a diagram that describes your system architecture.
• Quickly explain in words how the system works.
• State the three most important advantages of using this architecture.
• State the two most important disadvantages of using this architecture.
Solution
Architectural Pattern Name: (1 point)
Pipe-and-Filter.
Diagram: (2 points)
Description: (2 points)
The system consists of multiple filters which are linked in sequence. An incoming email is
given to the first filter. Then, each filter either moves the Email to a destination (inbox,
trash, spam), or hands it off to the next filter. The emails that are left at the end will go to
the inbox.
• Scalability: Individual filters can be run in parallel when the system moves to a multi-
core machine.
• Extendibility: Filters can be added or removed without affecting the overall system.
3
ETHZ D-INFK
Prof. Dr. B. Meyer Software Architecture – Exam
Solution
Architectural Pattern Name: (1 point)
Event-based.
Diagram: (2 points)
Description: (2 points)
The system consists of a data repository, which stores the current values of all sensor
data. Different checkers can subscribe for changes in different data types. When the data
sources generate new data, the data repository informs the subscribed checkers that new
data is available. The data checkers are individual modules and thus can perform their
checks in parallel as soon as new data is available.
4
Legi-Nr.:...............................................
• Integrity of checks: The checks are done independent of each other, so they could
possibly launch contradicting actions as a result of the check.
• Data repository is single point of failure.
5
ETHZ D-INFK
Prof. Dr. B. Meyer Software Architecture – Exam
feature
make
−− Create an empty list.
ensure
count = 0
index = 1
count: INTEGER
−− Number of items in the list
index: INTEGER
−− Index of current cursor position ( is between 1...( count+1))
after : BOOLEAN
−− Is there no valid cursor position to the right of cursor?
ensure
Result = (index = count + 1)
is empty: BOOLEAN
−− Is structure empty?
ensure
is empty = (count = 0)
start
−− Move cursor to first position .
ensure
index = 1
forth
−− Move cursor to next position.
require
not after
ensure
index = old index + 1
6
Legi-Nr.:...............................................
do
[2] p := new cell (v)
[3] if is empty then
[4] first element := p
[5] active := p
else
[6] l := last element
[7] if l /= Void then
[8] l . put right (p)
[9] if after then
[10] active := p
end
end
end
[11] count := count + 1
ensure
count = old count + 1
index = old index
end
extend adds an element to the end of a LINKED LIST. first element and last element point to
the first and the last element in the list, respectively. If the list is empty, first element and
last element are Void. active points to the element at the current cursor position. If the cursor
is off the list, active is Void.
In program analysis:
7
ETHZ D-INFK
Prof. Dr. B. Meyer Software Architecture – Exam
Questions
(1) Please find all definitions of variables in the above listing. (1 point each)
p[2]
first element[4]
active[5]
l[6]
active[10]
count[11]
(2) Please find all def-use pairs for the definitions listed in question (1). For each def-use
pair, use the described notation io indicate it is a P-use or a C-use. (1 point each)
p[2-4]C
p[2-5]C
l[6-7]P
l[6-8]C
p[2-8]C
p[2-10]C
count[11-11]C
(3) In software testing, the All def-use criterion is a data-flow coverage criterion, it is
satisfied if all def-use pairs are examined by at least one test case. Please construct a test
suite which satisfies all def-use criterion for local variable p.
create l.make
l .extend (Void)
create l.make
l .extend (Void)
l . start
l . forth
l .extend (Void)