Ch4 Software Design
-
Upload
sujit-karande -
Category
Documents
-
view
221 -
download
0
Transcript of Ch4 Software Design
-
8/13/2019 Ch4 Software Design
1/118
Ch. 4 1
Design and Software
Architecture
-
8/13/2019 Ch4 Software Design
2/118
Ch. 4 2
Outline What is design
How can a system be decomposed into modules
What is a modules interface
What are the main relationships among modules
Prominent software design techniques andinformation hiding
The UML collection of design notations
Design of concurrent and distributed software
Design patterns
Architectural styles
Component based software engineering
-
8/13/2019 Ch4 Software Design
3/118
-
8/13/2019 Ch4 Software Design
4/118
Ch. 4 4
Two meanings of "design
activity in our contextActivity that acts as a bridge between
requirements and the implementation
of the softwareActivity that gives a structure to the
artifact e.g., a requirements specification
document must be designed must be given a structure that makes it easy to
understand and evolve
-
8/13/2019 Ch4 Software Design
5/118
Ch. 4 5
The sw design activity
Defined as system decomposition intomodules
Produces a Software Design Document
describes system decomposition intomodules
Often a software architectureisproduced prior to a software design
-
8/13/2019 Ch4 Software Design
6/118
Ch. 4 6
Software architecture Shows gross structure and organization of the
system to be defined
Its description includes description of
main components of a system
relationships among those components
rationale for decomposition into its components
constraints that must be respected by any designof the components
Guides the development of the design
-
8/13/2019 Ch4 Software Design
7/118
Ch. 4 7
Two important goals
Design for change (Parnas)
designers tend to concentrate on current
needs special effort needed to anticipate likely
changes
Product families (Parnas) think of the current system under design
as a member of a program family
-
8/13/2019 Ch4 Software Design
8/118
Ch. 4 8
Sample likely changes? (1)
Algorithms e.g., replace inefficient sorting algorithm
with a more efficient one Change of data representation
e.g., from binary tree to a threaded tree(see example)
17% of maintenance costs attributed todata representation changes (Lientz andSwanson, 1980)
-
8/13/2019 Ch4 Software Design
9/118
Ch. 4 9
Example
-
8/13/2019 Ch4 Software Design
10/118
Ch. 4 10
Sample likely changes? (2)
Change of underlying abstract machine new release of operating system
new optimizing compiler
new version of DBMS
Change of peripheral devices
Change of "social" environment
new tax regime EURO vs national currency in EU
Change due to development process(transform prototype into product)
-
8/13/2019 Ch4 Software Design
11/118
Ch. 4 11
Product families
Different versions of the same system e.g. a family of mobile phones
members of the family may differ in network
standards, end-user interaction languages, e.g. a facility reservation system
for hotels: reserve rooms, restaurant,conference space, , equipment (video
beamers, overhead projectors, ) for a university
many functionalities are similar, some are different(e.g., facilities may be free of charge or not)
-
8/13/2019 Ch4 Software Design
12/118
Ch. 4 12
Design goal for family
Design the whole family as one system,not each individual member of the
family separately
-
8/13/2019 Ch4 Software Design
13/118
Ch. 4 13
Sequential completion:
the wrong way Design first member of product family
Modify existing software to get nextmember products
-
8/13/2019 Ch4 Software Design
14/118
Ch. 4 14
Sequential completion:a graphical view
Requirements
1
2
3
Version 1
Version 1
Version 25
Requirements
1
2
3
4 6
7 Version 3
4
Requirements
1
2
3
Version 2 5
Version 1
4
intermediatedesign
finalproduct
-
8/13/2019 Ch4 Software Design
15/118
Ch. 4 15
How to do better
Anticipate definition of all familymembers
Identify what is common to all familymembers, delay decisions thatdifferentiate among different members
We will learn how to manage change indesign
-
8/13/2019 Ch4 Software Design
16/118
Ch. 4 16
Module
A well-defined component of a softwaresystem
A part of a system that provides a setof services to other modules
Services are computational elements that
other modules may use
-
8/13/2019 Ch4 Software Design
17/118
Ch. 4 17
Questions
How to define the structure of amodular system?
What are the desirable properties ofthat structure?
-
8/13/2019 Ch4 Software Design
18/118
Ch. 4 18
Modules and relations
Let S be a set of modules
S = {M1, M2, . . ., Mn}
A binary relation r on S is a subset of
S x S
If Miand Mjare in S,
r canbe written as Mi r Mj
-
8/13/2019 Ch4 Software Design
19/118
Ch. 4 19
Relations
Transitive closure r+ of r
Mi r+ Mj iff
Mi r Mj or Mkin S s.t. Mi r Mkand Mk r
+ Mj(We assume our relations to be irreflexive)
r is a hierarchy iff there are no twoelements Mi, Mjs.t. Mi r
+ Mj Mj r+ Mi
-
8/13/2019 Ch4 Software Design
20/118
-
8/13/2019 Ch4 Software Design
21/118
Ch. 4 21
The USES relation
A uses B
A requires the correct operation of B
A can access the services exported by Bthrough its interface
it is statically defined
A depends on B to provide its services example: A calls a routine exported by B
A is a client of B; B is a server
-
8/13/2019 Ch4 Software Design
22/118
Ch. 4 22
Desirable property
USES should be a hierarchy
Hierarchy makes software easier to
understand we can proceed from leaf nodes (who do
not use others) upwards
They make software easier to build They make software easier to test
-
8/13/2019 Ch4 Software Design
23/118
Ch. 4 23
Hierarchy
Organizes the modular structurethrough levels of abstraction
Each level defines an abstract (virtual)machinefor the next level
level can be defined precisely
Mihas level 0 if no Mjexists s.t. Mir Mj let k be the maximum level of all nodes Mj s.t.
Mir Mj. Then Mihas level k+1
-
8/13/2019 Ch4 Software Design
24/118
Ch. 4 24
IS_COMPONENT_OF
Used to describe a higher level module asconstituted by a number of lower level modules
A IS_COMPONENT_OF B
B consists of several modules, of which one is A
B COMPRISES A
MS,i={Mk|MkSMkIS_COMPONENT_OF Mi}
we say that MS,i IMPLEMENTS Mi
-
8/13/2019 Ch4 Software Design
25/118
Ch. 4 25
A graphical view
M1
M M
M MM M M
2 4
5 67 8 9
M3
M MM M M5 67 8 9
M2
M
3
M
4
M1
(IS_COMPONENT_OF) (COMPRISES)
They are a hierarchy
-
8/13/2019 Ch4 Software Design
26/118
Ch. 4 26
Product families
Careful recording of (hierarchical) USESrelation and IS_COMPONENT_OF
supports design of program families
-
8/13/2019 Ch4 Software Design
27/118
Ch. 4 27
Interface vs. implementation (1)
To understand the nature of USES, weneed to know what a used module
exportsthrough its interface The client importsthe resources that
are exported by its servers
Modules implementthe exportedresources
Implementation is hiddento clients
-
8/13/2019 Ch4 Software Design
28/118
Ch. 4 28
Interface vs. implementation (2)
Clear distinction between interface andimplementation is a key design principle
Supports separation of concerns clients care about resources exported from
servers
servers care about implementation
Interface acts as a contract between amodule and its clients
-
8/13/2019 Ch4 Software Design
29/118
Ch. 4 29
Interface vs. implementation (3)
interface is like the tip of the iceberg
-
8/13/2019 Ch4 Software Design
30/118
Ch. 4 30
Information hiding
Basis for design (i.e. module decomposition)
Implementation secrets are hidden to clients
They can be changed freely if the changedoes not affect the interface
Golden design principle
INFORMATION HIDING
Try to encapsulate changeable design decisions asimplementation secrets within module implementations
H t d i d l
-
8/13/2019 Ch4 Software Design
31/118
Ch. 4 31
How to design moduleinterfaces?
Example: design of an interpreter forlanguage MINI We introduce a SYMBOL_TABLEmodule
provides operations to CREATE an entry for a new variable
GET the value associated with a variable
PUT a new value for a given variable
the module hides the internal data
structure of the symbol table the data structure may freely change
without affecting clients
-
8/13/2019 Ch4 Software Design
32/118
Ch. 4 32
Interface design
Interface should not reveal what weexpect may change later
It should not reveal unnecessary details
Interface acts as a firewall preventingaccess to hidden parts
-
8/13/2019 Ch4 Software Design
33/118
Ch. 4 33
Prototyping
Once an interface is defined,implementation can be done
first quickly but inefficiently then progressively turned into the final
version
Initial version acts as a prototype thatevolves into the final product
-
8/13/2019 Ch4 Software Design
34/118
Ch. 4 34
More on likely changes
an example Policiesmay be separated from
mechanisms
mechanism ability to suspend and resume tasks in a concurrent
system
policy
how do we select the next task to resume? different scheduling policies are available
they may be hidden to clients
they can be encapsulated as module secrets
-
8/13/2019 Ch4 Software Design
35/118
Ch. 4 35
Design notations
Notations allow designs to be describedprecisely
They can be textual or graphic We illustrate two sample notations
TDN (Textual Design Notation)
GDN (Graphical Design Notation) We discuss the notations provided by
UML
-
8/13/2019 Ch4 Software Design
36/118
Ch. 4 36
TDN & GDN
Illustrate how a notation may help indocumenting design
Illustrate what a generic notation maylook like
Are representative of many proposednotations
TDN inherits from modern languages,like Java, Ada,
-
8/13/2019 Ch4 Software Design
37/118
Ch. 4 37
An examplemoduleX
usesY, Z
exportsvarA : integer;
typeB : array (1. .10) ofreal;
procedureC ( D: inoutB; E: ininteger; F: inreal);Here is an optional natural-language description of what
A, B, and C actually are, along with possible constraints or properties that clients need to know; for example, we
might specify that objects of type B sent to procedure Cshould be initialized by the client and should never
contain all zeroes.implementationIf needed, here are general comments about the rationaleof the modularization, hints on the implementation, etc.
is composed of R, T
endX
-
8/13/2019 Ch4 Software Design
38/118
Ch. 4 38
Comments in TDN
May be used to specify the protocoltobe followed by the clients so that
exported services are correctly provided e.g., a certain operation which does the
initialization of the module should be calledbefore any other operation
e.g., an insert operation cannot be called ifthe table is full
-
8/13/2019 Ch4 Software Design
39/118
Ch. 4 39
Example (cont.)module Ruses Yexports varK :record . . .end;
type B :array (1. .10) ofreal;procedure C (D: in out B; E:ininteger; F:in real);
implementation...
end R
module Tuses Y, Z, R
exports varA : integer;implementation
.
.
.
end T
-
8/13/2019 Ch4 Software Design
40/118
Ch. 4 40
Benefits
Notation helps describe a designprecisely
Design can be assessed for consistency having defined module X, modules R and T
must be defined eventually
if not incompleteness R, T replace X
either one or both must use Y, Z
-
8/13/2019 Ch4 Software Design
41/118
Ch. 4 41
Example: a compilermodule COMPILER
exports procedure MINI (PROG: in file of char;CODE: out file of char);
MINI is called to compile the program stored in PROGand produce the object code in file CODE
implementationA conventional compiler implementation.ANALYZER performs both lexical and syntactic analysisand produces an abstract tree, as well as entries in thesymbol table; CODE_GENERATOR generates code
starting from the abstract tree and information storedin the symbol table. MAIN acts as a job coordinator.
is composed of ANALYZER, SYMBOL_TABLE,ABSTRACT_TREE_HANDLER, CODE_GENERATOR, MAIN
end COMPILER
h d l
-
8/13/2019 Ch4 Software Design
42/118
Ch. 4 42
Other modulesmodule MAINuses ANALYZER, CODE_GENERATOR
exports procedure MINI (PROG: in file of char;CODE: out file of char);
end MAIN
module ANALYZERuses SYMBOL_TABLE, ABSTRACT_TREE_HANDLERexports procedure ANALYZE (SOURCE: in file of char);
SOURCE is analyzed; an abstract tree is producedby using the services provided by the tree handler,and recognized entities, with their attributes, arestored in the symbol table....
end ANALYZER
-
8/13/2019 Ch4 Software Design
43/118
Ch. 4 43
Other modules
module CODE_GENERATORuses SYMBOL_TABLE, ABSTRACT_TREE_HANDLERexports procedure CODE (OBJECT: out file of char);
The abstract tree is traversed by using theoperations exported by theABSTRACT_TREE_HANDLER and accessingthe information stored in the symbol table
in order to generate code in the output file.
end CODE_GENERATOR
-
8/13/2019 Ch4 Software Design
44/118
Ch. 4 44
GDN description of module X
X
Y
ZA B
R TModuleModule
Module
Module
Module
C
-
8/13/2019 Ch4 Software Design
45/118
Ch. 4 45
X's decomposition
-
8/13/2019 Ch4 Software Design
46/118
Ch. 4 46
Categories of modules
Functional modules
traditional form of modularization
provide a procedural abstraction encapsulate an algorithm
e.g. sorting module, fast Fourier transformmodule,
-
8/13/2019 Ch4 Software Design
47/118
Ch. 4 47
Categories of modules (cont.)
Libraries
a group of related procedural abstractions
e.g., mathematical libraries implemented by routines of programming languages
Common pools of data
data shared by different modules e.g., configuration constants the COMMON FORTRAN construct
-
8/13/2019 Ch4 Software Design
48/118
Ch. 4 48
Categories of modules (cont.)
Abstract objects
Objects manipulated via interface functions
Data structure hidden to clients
Abstract data types
Many instances of abstract objects may be
generated
-
8/13/2019 Ch4 Software Design
49/118
Ch. 4 49
Abstract objects: an example
A calculator of expressions expressed inPolish postfix form
a*(b+c)
abc+* a module implements a stack where the
values of operands are shifted until anoperator is encountered in the
expression(assume only binary operators)
-
8/13/2019 Ch4 Software Design
50/118
Ch. 4 50
Example (cont.)
exportsprocedure PUSH (VAL: in integer);procedure POP_2 (VAL1, VAL2: out integer);
Interface of the abstract object STACK
-
8/13/2019 Ch4 Software Design
51/118
Ch. 4 51
Design assessment
How does the design anticipate changein type of expressions to be evaluated?
e.g., it does not adapt to unary operators
-
8/13/2019 Ch4 Software Design
52/118
Ch. 4 52
Abstract data types (ADTs)
A stack ADT
module STACK_HANDLER
exportstype STACK = ?;This is an abstract data-type module; the data structureis a secret hidden in the implementation part.
procedure PUSH (S: in out STACK ; VAL: in integer);
procedure POP (S: in out STACK ; VAL: out integer);function EMPTY (S: in STACK) : BOOLEAN;...
end STACK_HANDLER
indicates that details of thedata structure are hidden
to clients
-
8/13/2019 Ch4 Software Design
53/118
Ch. 4 53
ADTs
Correspond to Java and C++ classes
Concept may also be implemented by Ada
private types and Modula-2 opaque types May add notational details to specify if certain
built-in operations are available by default oninstance objects of the ADT
e.g., type A_TYPE: ? (:=, =) indicates thatassignment and equality check are available
An example:
-
8/13/2019 Ch4 Software Design
54/118
Ch. 4 54
An example:simulation of a gas station
module FIFO_CARSuses CARSexports
type QUEUE : ?;
procedure ENQUEUE (Q: in out QUEUE ; C: in CARS);procedure DEQUEUE (Q: in out QUEUE ; C: out CARS);function IS_EMPTY (Q: in QUEUE) : BOOLEAN;function LENGTH (Q: in QUEUE) : NATURAL;procedure MERGE (Q1, Q2 : in QUEUE ; Q : out QUEUE);This is an abstract data-type module representing
queues of cars, handled in a strict FIFO way;queues are not assignable or checkable for equality,since := and = are not exported.
end FIFO_CARS
-
8/13/2019 Ch4 Software Design
55/118
Ch. 4 55
Generic modules (templates)
They are parametric wrt a type
generic module GENERIC_STACK_2
. . .exports
procedure PUSH (VAL : in T);procedure POP_2 (VAL1, VAL2 : out T);
end GENERIC_STACK_2
-
8/13/2019 Ch4 Software Design
56/118
Ch. 4 56
Instantiation
Possible syntax:
module INTEGER_STACK_2 is
GENERIC_STACK_2 (INTEGER)
-
8/13/2019 Ch4 Software Design
57/118
Ch. 4 57
More on genericity
How to specify that besides a type also anoperation must be provided as a parameter
generic module M (T) with OP(T)
uses ...
...
end M
Instantiationmodule M_A_TYPE is M(A_TYPE) PROC(M_A_TYPE)
-
8/13/2019 Ch4 Software Design
58/118
Ch. 4 58
Specific techniques for
design for change
Use of configuration constants
factoring constant values into symbolicconstants is a common implementationpractice
e.g., #define in C
#define MaxSpeed 5600;
Specific techniques for
-
8/13/2019 Ch4 Software Design
59/118
Ch. 4 59
Specific techniques fordesign for change (cont.)
Conditional compilation...source fragment common to all versions...
# ifdef hardware-1
...source fragment for hardware 1 ...
# endif
#ifdef hardware-2
...source fragment for hardware 2 ...
# endif
Software generation e.g., compiler compilers (yacc, interface
prototyping tools)
-
8/13/2019 Ch4 Software Design
60/118
Ch. 4 60
Stepwise refinement
A systematic, iterative program designtechnique that unfortunately may lead to
software that is hard to evolveAt each step, problem P decomposed into
sequence of subproblems: P1; P2; Pn
a selection: if (cond) then P1 else P2 an iteration: while (cond) do_something
-
8/13/2019 Ch4 Software Design
61/118
Ch. 4 61
Example
derivation of selection sortStep 1
let n be the length of the array a to be sorted;i := 1 ;
while i < n loopfind the smallest of ai .. .an, and exchangeit with the element at position i;i := i + 1;
end loop;
-
8/13/2019 Ch4 Software Design
62/118
Ch. 4 62
Step 2let n be the length of the array a to be sorted;i := 1 ;
while i < n loopj := n;while j > i loop
if a(i) > a(j) then
interchange the elements atpositions j and i ;
end if;j := j - 1;
end loop;i := i + 1;
end loop;
-
8/13/2019 Ch4 Software Design
63/118
Ch. 4 63
Step 3let n be the length of the array a to be sorted;
i := 1 ;while i < n loopj := n;while j > i loop
if a(i) > a(j) then
x := a(i);a(i) := a(j);a(j) := x;
end if;
j := j - 1;end loop;i := i + 1;
end loop;
-
8/13/2019 Ch4 Software Design
64/118
Ch. 4 64
Decomposition tree
Stepwise refinement process may bedepicted by a decomposition tree (DT)
root labeled by name of top problem subproblem nodes labeled as children of
parent node corresponding to problem
children from left to right representsequential order of execution
if and while nodes denoted by suitabledecoration
Example
-
8/13/2019 Ch4 Software Design
65/118
Ch. 4 65
ExampleStep 1P; P problem to solve
Step 2
P1; P2; P3; P decomposed into sequenceStep 3
P1;while C loop
P2,1; P2 decomposed into a loopend loop;P3;
Step 4
P1;while C loop
if C1 then P2,1 decomposed into selection
P2,1,1;else
P2,1,2;end if;
end loop;
P3;
-
8/13/2019 Ch4 Software Design
66/118
Ch. 4 66
Corresponding DT
P
P1
P2
P3
P2,1
P2,1, 1
P2,1, 2
C
C1 notC1
-
8/13/2019 Ch4 Software Design
67/118
Ch. 4 67
Relation with
IS_COMPOSED_OF Let M, M1, M2, M3 be modules
representing P, P1, P2, P3
We cannot write M IS_COMPOSED_OF {M1,M2,M3}
We need to add further module acting
as glue to impose a sequential flowfrom M1 to M2 to M3
-
8/13/2019 Ch4 Software Design
68/118
Ch. 4 68
An assessment of stepwise
refinement (1) Stepwise refinement is a programmingtechnique, not a modularizationtechnique
When used to decompose system intomodules, it tends to analyze problemsin isolation, not recognizing
commonalities It does not stress information hiding
-
8/13/2019 Ch4 Software Design
69/118
Ch. 4 69
An assessment of stepwise
refinement (2) No attention is paid to data (it
decomposes functionalities)
Assumes that a top function exists but which one is it in the case of an
operating system? or a word processor?
Enforces premature commitment tocontrol flow structures among modules
-
8/13/2019 Ch4 Software Design
70/118
Step 3
-
8/13/2019 Ch4 Software Design
71/118
Ch. 4 71
correct := true;perform lexical analysis:
store program as token sequence in file ft
and symbol table in file fs, and set error_in_lexical_phaseaccordingly;if error_in_lexical_phase then
correct := false;else
perform syntactic analysis and set Boolean variableerror_in_syntactic_phase accordingly:if error_in_syntactic_phase then
correct := false;end if;
end if;
if correct thenprint message"program correct";
elseprint message"program incorrect";
end if;
-
8/13/2019 Ch4 Software Design
72/118
Ch. 4 72
Commitments
Two passes
Lexical analysis comes first on the entire
program, producing two files What if we want to switch to a process
driven by syntax analysis (it requests
the lexical analyzer to provide a tokenwhen needed)
everything changes!!!
d d
-
8/13/2019 Ch4 Software Design
73/118
Ch. 4 73
A better design based on
information hiding Module CHAR_HOLDER hides physical representation of input file
exports operation to access source file on a
character-by-character basis Module SCANNER
hides details of lexical structure of the language
exports operation to provide next token
Module PARSER hides data structure used to perform syntactic
analysis (abstract object PARSER)
-
8/13/2019 Ch4 Software Design
74/118
Ch. 4 74
Top-down vs. bottom-up
Information hiding proceeds bottom-up Iterated application of IS_COMPOSED_OF
proceeds top-down
stepwise refinement is intrinsically top-down Which one is best?
in practice, people proceed in both directions yo-yo design
organizing documentation as a top-downflow may be useful for reading purposes,even if the process followed was not top-down
-
8/13/2019 Ch4 Software Design
75/118
Ch. 4 75
Handling anomalies
Defensive design
A module is anomalousif it failsto
provide the service as expected and asspecified in its interface
An exceptionMUST be raised when
anomalous state is recognized
H f il i ?
-
8/13/2019 Ch4 Software Design
76/118
Ch. 4 76
How can failures arise?
Module M should fail and raise anexception if
one of its clients does not satisfy therequired protocolfor invoking one of Msservices
M does not satisfy the required protocolwhen using one of its servers, and the
server fails hardware generated exception (e.g.,
division by zero)
Wh d l d
-
8/13/2019 Ch4 Software Design
77/118
Ch. 4 77
What a module can do
before failing Before failing, modules may try torecover from the anomaly by executingsome exception handler (EH) EH is a local piece of code that may try to
recover from anomaly (if successful,module does not fail)
or may simply do some cleanup of themodules state and then let the module fail,signaling an exception to its client
-
8/13/2019 Ch4 Software Design
78/118
Ch. 4 78
Example
module Mexports . . .
procedure P (X: INTEGER; . . .)
raises X_NON_NEGATIVE_EXPECTED,INTEGER_OVERFLOW;X is to be posit ive; i f not, exceptionX_NON_NEGATIVE_EXPECTED is raised;INTEGER_OVERFLOW is raised if internalcomputation of P generates an overflow
.
.
.
end M
E l f ti
-
8/13/2019 Ch4 Software Design
79/118
Ch. 4 79
Example of exception
propagationmodule L
uses M imports P (X: INTEGER; . .)
exports . . .;
procedure R ( . . .)
raises INTEGER_OVERFLOW;...
implementationIf INTEGER_OVERFLOW is raised when P is invoked, the
exception is propagated...
end L
-
8/13/2019 Ch4 Software Design
80/118
Ch. 4 80
Case study
Compiler for the MIDI programminglanguage
The language is block-structured It requires a symbol table module that
can cope with block static nesting
We discuss here moduleSYMBOL_TABLE
-
8/13/2019 Ch4 Software Design
81/118
Ch. 4 81
SYMBOL_TABLE (vers.1)module SYMBOL_TABLE
Supports up to MAX_DEPTH block nesting levels
uses ... imports (IDENTIFIER, DESCRIPTOR)
exports procedure INSERT (ID: in IDENTIFIER;
DESCR:in DESCRIPTOR);procedure RETRIEVE (ID:in IDENTIFIER;DESCR:out DESCRIPTOR);
procedure LEVEL (ID: in IDENTIFIER; L:out INTEGER);
procedure ENTER_SCOPE;
procedure EXIT_SCOPE;
end SYMBOL_TABLE
procedure INIT (MAX_DEPTH: inINTEGER);
-
8/13/2019 Ch4 Software Design
82/118
Ch. 4 82
Version 1 is not robust
Defensive design should be applied
Exceptions must be raised in these cases:
INSERT: insertion cannot be done becauseidentifier with same name already exists incurrent scope
RETRIEVE and LEVEL: identifier with specifiedname not visible
ENTER_SCOPE: maximum nesting depth exceeded
EXIT_SCOPE: no matching block entry exists
SYMBOL TABLE (vers 2)
-
8/13/2019 Ch4 Software Design
83/118
Ch. 4 83
SYMBOL_TABLE (vers.2)module SYMBOL_TABLE
uses ... imports (IDENTIFIER, DESCRIPTOR)exports
Supports up to MAX_DEPTH block nesting levels; INITmust be called before any other operation is invokedprocedure INSERT (ID: in IDENTIFIER;
DESCR: in DESCRIPTOR)
raisesMULTIPLE_DEF,procedure RETRIEVE (ID:in IDENTIFIER;DESCR: out DESCRIPTOR)
raisesNOT_VISIBLE;
procedure LEVEL (ID: in IDENTIFIER;L: out INTEGER)
raises NOT_VISIBLE;
procedure ENTER_SCOPEraises EXTRA_LEVELS;
procedure EXIT_SCOPEraises EXTRA_END;
end SYMBOL_TABLE
procedure INIT (MAX_DEPTH: inINTEGER);
SYMBOL TABLE li t
-
8/13/2019 Ch4 Software Design
84/118
Ch. 4 84
SYMBOL_TABLE uses a list
management modulegeneric module LIST(T)withMATCH (EL_1,EL_2:inT)exports
type LINKED_LIST:?;procedure IS_EMPTY (L:inLINKED_LIST): BOOLEAN;
Tel ls whether the l ist is empty.procedure SET_EMPTY (L:in out LINKED_LIST);Sets a l ist to empty.procedure INSERT (L:in out LINKED_LIST; EL:inT);Inserts the element into the list
procedure SEARCH (L: inLINKED_LIST; EL_1:inT;EL_2: out T; FOUND:out boolean);
Searches L to find an element EL_2 thatmatches EL_1 and returns the resu lt i n FOUND.
end LIST(T)
-
8/13/2019 Ch4 Software Design
85/118
Ch. 4 85
Concurrent software The case of a module defining shared data
E.g., abstract object BUFFER module QUEUE_OF_CHAR is
GENERIC_FIFO_QUEUE (CHAR)
BUFFER : QUEUE_OF_CHAR.QUEUE
with operations PUT: inserts a character in BUFFER
GET: extracts a character from BUFFER NOT_FULL: returns true if BUFFER not full
NOT_EMPTY: returns true if BUFFER not empty
How to control correct
-
8/13/2019 Ch4 Software Design
86/118
Ch. 4 86
access to shared data? Not sufficient that clients check
operation invocations, such asif QUEUE_OF_CHAR.NOT_FULL (BUFFER) then
QUEUE_OF_CHAR.PUT (X, BUFFER);end if;
Consumer_1 and Consumer_2 might dothis concurrently
if only one slot is left, both may find the buffernot full, the first who writes fills it, and theother writes in a full buffer
-
8/13/2019 Ch4 Software Design
87/118
Ch. 4 87
Enforcing synchronization
Ensure that operations on buffer areexecuted in mutual exclusion
Ensure that operations such asif QUEUE_OF_CHAR.NOT_FULL (BUFFER) then
QUEUE_OF_CHAR.PUT (X, BUFFER);
end if;
are executed as logically non-interruptible units
-
8/13/2019 Ch4 Software Design
88/118
Ch. 4 88
Monitors
Abstract objects used in a concurrentenvironment
Available in the Java programminglanguage
M it l
-
8/13/2019 Ch4 Software Design
89/118
Ch. 4 89
Monitors: an example
concurrent module CHAR_BUFFERThis is a monitor, i.e., an abstract object module in a concurrent environment
uses . . .
exports
procedure PUT (C : in CHAR) requires NOT_FULL;procedure GET (C: out CHAR) requires NOT_EMPTY;NOT_EMPTY and NOT_FULL are hidden Booleanfunctions yielding TRUE if the buffer is not empty and notfull, respectively. They are not exported as operations,because their purpose is only to delay the calls to PUT andGET if they are issued when the buffer is in a state where itcannot accept them...
end CHAR_BUFFER
-
8/13/2019 Ch4 Software Design
90/118
-
8/13/2019 Ch4 Software Design
91/118
Ch. 4 91
Monitor types: an example
generic concurrent module GENERIC_FIFO_QUEUE (EL)This is a generic monitor type, i.e., an abstract data typeaccessed in a concurrent environment
uses . . .
exportstype QUEUE: ?;
procedure PUT (Q1: in out QUEUE; E1: in EL)
requires NOT_FULL (Q1: QUEUE);
procedure GET (Q2: in out QUEUE; E2: out EL)
requires NOT_EMPTY(Q2: QUEUE);...
end GENERIC_FIFO_QUEUE (EL)
-
8/13/2019 Ch4 Software Design
92/118
Ch. 4 92
Guardians and rendez-vous
The Ada style of designing concurrentsystems
In Ada a shared object is active(whereas a monitor is passive)
it is managed by a guardianprocess which
can accept rendez-vous requests fromtasks willing to access the object
A guardian task
-
8/13/2019 Ch4 Software Design
93/118
Ch. 4 93
A guardian task
loopselect
when NOT_FULLaccept PUT (C: inCHAR);This is the body of PUT; the cl ient cal ls it as i
were a normal procedureend ;
orwhen NOT_EMPTY
accept GET (C:out CHAR);
This is the body of GET; the client calls i t as iwere a normal procedureend ;
end select ;end loop ;
note nondeterministic acceptance of
rendez-vous requests
Real time software
-
8/13/2019 Ch4 Software Design
94/118
Ch. 4 94
Real-time software
Case where processes interact with theenvironment
E.g., a put operation on a shared buffer
is invoked by a plant sensor sendingdata to a controller
plant cannot be suspended if buffer full!
design must ensure that producer never findsthe buffer full
this constrains the speed of the consumer process inthe controller
-
8/13/2019 Ch4 Software Design
95/118
Ch. 4 95
TDN description
concurrent module REACTIVE_CHAR_BUFFERThis is a monitorlike object working in a real-time environment.
uses . . .
exports
reactive procedure PUT (C: in CHAR);PUT is used by external processes, and two consecutive PUT requests must arrive more than 5 msec apart;otherwise, some characters may be lostprocedure GET (C: out CHAR);
..
.end REACTIVE_CHAR_BUFFER
-
8/13/2019 Ch4 Software Design
96/118
Ch. 4 96
GDN description
Module
REACTIVE_CHAR_BUFFER
PUT GET
zig-zag arrow indicates asynchronous invocation
-
8/13/2019 Ch4 Software Design
97/118
-
8/13/2019 Ch4 Software Design
98/118
Ch. 4 98
Client-server architecture
The most popular distributedarchitecture
Server modules provide services toclient modules
Clients and servers may reside on
different machines
-
8/13/2019 Ch4 Software Design
99/118
-
8/13/2019 Ch4 Software Design
100/118
Ch. 4 100
Middleware
Layer residing between the networkoperating system and the application
Helps building network applications Provides useful services
Name services, to find processes or
resources on the network Communication services, such as message
passing or RPC (or RMI)
-
8/13/2019 Ch4 Software Design
101/118
Ch. 4 101
Object-oriented design
One kind of module, ADT, called class
A class exports operations (procedures)
to manipulate instance objects often called methods
Instance objects accessible via
references
-
8/13/2019 Ch4 Software Design
102/118
Ch. 4 102
Syntactic changes in TDN
No need to export opaque types
class name used to declare objects
If a is a reference to an object a.op (params);
A further relation:
-
8/13/2019 Ch4 Software Design
103/118
Ch. 4 103
A further relation:
inheritanceADTs may be organized in a hierarchy Class B may specialize class A
B inherits from Aconversely, A generalizes B
A is a superclass of B
B is a subclass of A
-
8/13/2019 Ch4 Software Design
104/118
-
8/13/2019 Ch4 Software Design
105/118
Ch. 4 105
class ADMINISTRATIVE_STAFF inheritsEMPLOYEEexports
procedureDO_THIS (F: FOLDER);This is an additional operation that is specific toadministrators; other operations may also be added.
endADMINISTRATIVE_STAFF
class TECHNICAL_STAFF inheritsEMPLOYEE
exportsfunctionGET_SKILL(): SKILL;procedureDEF_SKILL (SK: SKILL);These are additional operations that are specific totechnicians; other operations may also be added.
endTECHNICAL_STAFF
Inheritance
-
8/13/2019 Ch4 Software Design
106/118
Ch. 4 106
Inheritance
A way of building software incrementallyA subclass defines a subtype subtype is substitutablefor parent type
Polymorphism a variable referring to type A can refer to an
object of type B if B is a subclass of A
Dynamic binding
the method invoked through a referencedepends on the type of the object associatedwith the reference at runtime
How can inheritance be
-
8/13/2019 Ch4 Software Design
107/118
Ch. 4 107
How can inheritance be
represented? We start introducing the UML notation UML (Unified Modeling Language) is a
widely adopted standard notation forrepresenting OO designs
We introduce the UML class diagram
classes are described by boxes
UML representation of
-
8/13/2019 Ch4 Software Design
108/118
Ch. 4 108
UML representation of
inheritanceEMPLOYEE
TECHNICAL_STAFFADMINISTRATIVE_STAFF
UML associations
-
8/13/2019 Ch4 Software Design
109/118
Ch. 4 109
Associations are relations that theimplementation is required to support
Can have multiplicity constraints
TECHNICAL_STAFF
MANAGER
PROJECT* 1
project_member
1
1..*
manages
-
8/13/2019 Ch4 Software Design
110/118
Ch. 4 110
Aggregation
Defines a PART_OF relation
Differs from IS_COMPOSED_OF
Here TRANGLE has its own methodsIt implicitly uses POINT to define
its data attributes
TRIANGLE
POINT
1
3
-
8/13/2019 Ch4 Software Design
111/118
Ch. 4 111
More on UML
Representation of IS_COMPONENT_OFvia the packagenotation
package_name
Class 1
Class 2
Class 3
f h
-
8/13/2019 Ch4 Software Design
112/118
Ch. 4 112
Software architecture
Describes overall system organizationand structure in terms of its major
constituents and their interactions Standard architectures can be identified
pipeline
blackboard event based (publish-subscribe)
d d h
-
8/13/2019 Ch4 Software Design
113/118
Ch. 4 113
Standard architectures
pipeline
event based
blackboard
Domain specific
-
8/13/2019 Ch4 Software Design
114/118
Ch. 4 114
Domain specific
architectures"modelviewcontroller" architecture for softwarethat has a significant amount of user interaction
Model (storedata e.g. text)
Controller
(interact with user;perform commands)
View (display modelfor user)
f
-
8/13/2019 Ch4 Software Design
115/118
Ch. 4 115
Software components
Goal
build systems out of pre-existing libraries
of components as most mature engineering areas do
Examples
STL for C++ JavaBeans and Swing for Java
C i i
-
8/13/2019 Ch4 Software Design
116/118
Ch. 4 116
Component integration
The CORBA (Common Object Request BrokerArchitecture) Middleware
Clients and servers connected via an ObjectRequest Broker (ORB)
Interfaces provided by servers defined by anInterface Definition Language (IDL)
In the Microsoft world: DCOM (DistributedComponent Object Model)
Th CORBA hi
-
8/13/2019 Ch4 Software Design
117/118
Ch. 4 117
The CORBA architecture
Ob ect Re uest Broker
CORBA Services
Application
ObjectsDomain
InterfacesCORBA
Facilities
Architectures fordistributed systems
-
8/13/2019 Ch4 Software Design
118/118
distributed systems
From two tiered
Client-server
to three tiered
Requests
for service(database)
Web browser
(client)
Web server
(server)Requests
for service
(pages)
User interface
(client)
Decode
service
request
(2nd
tier)
Application
server(databse)