Structure Programming Chapter 3
Structure Programming Chapter 3
Architecture
1
What is software design ?
• Design as an activity: acts as a bridge between
requirements and the implementation of the
system
– Decompose system into modules
– Assign responsibilities to these modules
– Ensure that these modules fit together to achieve a
global goal
• Design as a result of an activity: gives a structure
that makes the system easy to understand and
evolve
– Produce a Software Design Document
– Often a software architecture is produced prior to a
software design
2
Covered topics
• Introduction
• Divide and conquer strategy
• Modularization techniques
• Architecture
3
Objectives
4
Recalled questions
Structured levels of
Software design
program
• Problem-solving • Architectural design
• Program • High-level design (API)
abstraction/organization
• Program elements • Detailed design (Impl.)
5
I. DIVIDE AND CONQUER
STRATEGY
1. Introduction
2. Decomposition
3. Composition
4. Step refinement
7
Introduction
Problem
Sub - P …. Sub - P
9
1.1. Functional decomposition
10
Example: abstract machine
Produce tea
sequence
add boiling
Put tea in pot wait
water
repetition
selection
11
Working: Banking system
Transfer Deposit
Withdraw
12
1.2. Algorithmic decomposition
13
Example: abstract machine
produce tea
sequence
condition
add boiling
put tea in pot wait
water
repetition
condition
pour spoon tea
into pot
selection
condition
fetch green fetch black
tea tea
14
Working: Banking system
Transfer Deposit
Withdraw
15
1.3. Object-oriented decomposition
16
Example: abstract machine
action
add boiling
Put tea in pot wait
water
Pot
Data
Cup
17
Exercise: Banking system
Transfer Deposit
Withdraw
18
2. Composition: bottom-up
19
3. Stepwise refinement: top-down
• Iterative process
• Operations and their associated data in every
step of an algorithm are the keys to solve a
problem
• Given an abstract machine implementing the
whole solution, refining the solution includes:
– Operation refinement: refine the operations in every
step of the corresponding algorithm
– Data refinement: refine the structures of data in every
step of the corresponding algorithm
20
2. Stepwise refinement: top-down
• Iterative process:
– Start: overall description of the problem to be solved
(top function)
– Decompose (in a recursive manner) the problem into
sub-problems according to control structures
– Terminate: when each sub-problems is easy to express
in terms of a few lines of code in the chosen
programming language.
• Bad:
– we might never reach a realization
– often “warehouse solutions” are developed
21
Decomposition tree
22
Example
Produce tea
add boiling
Put tea in pot wait
water
C1 not C1
23
Exercise: Banking system
Transfer Deposit
Withdraw
24
II. MODULARIZATION
TECHNIQUES
1. Module
2. Relations between modules
3. Specific techniques for design for change
25
1.1. What is a module ?
• Software system should, according to the divide-and-
conquer principle, also physically be divided into basic
parts, modules
– 1 module can be developed independently
• errors can be traced down to modules
• modules can be tested before assembling
But not normally be considered as neither a separate system nor an
independent system
– 1 module can be exchanged independently
– 1 module can provide a set of computational elements to other
modules
– modules can be reused
• The terms module and component are pretty much the
same: a module is a well-defined component of a software
system
– a programming-language supported component (often composite)
– a simple component
26
Questions
System
27
1.2. Principle of modularization
[Parnas72]
• Fix all design decisions that
are likely to change design design
• Attach each of those decision M
decision
1
decisions to a new module design design
• The design decision is now M2
decision decision
28
1.2. Principle of modularization
[Parnas72]
Secret
Implementation of
Module exported resources
31
II. MODULARIZATION
TECHNIQUES
1. Module
2. Relations between modules
3. Specific techniques for design for change
32
2.1. Definition
• Let S be a set of
modules M1
S = {M1, M2, . ., Mn}
• A binary relation r M2
on S is a subset of
… r
SxS
• If Mi and Mj Î S, Mn-1
Mn
a pair <Mi, Mj> Î r
can be written as
System
Mi r Mj
33
2.2. Classification
• delegates-to (delegation)
• is-a (inheritance)
M1
• has-a (aggregation)
• is-component-of,
comprises (composition) M2
• accesses-a (access … r
relation)
• is-privileged-to, owns-a Mn-1
(security) Mn
• calls
• is-called-by System
• relies-on (uses)
34
2.3. USES relation: A uses B
• Module A uses (relies-on) module B iff A
requires a correct implementation of B for its
own correct execution. A
– It is “statically” defined
– A is a client of B; B is a server
• Requires an implementation may mean:
– A delegates work to B (delegation relation)
– A accesses a variable of B through the B’s
uses
interface (access relation)
– A depends on B to provide its functions: A calls B
OR B calls A B
• The uses relation may be a partial order (a tree
or a dag) or a total order, then the system is
called hierarchical or layered
• USES should be a hierarchy to make the
software easier to understand, build and test
35
Example:
modular representation with OOP
USES HAS IS
class B class B class B
{ { {
… … …
… … …
} } }
36
Hierarchy
• Organizes the modular
structure through levels of
abstraction
• Each level defines an M M level 0
abstract (virtual) machine 5 6
for the next level level 1
• Level can be defined M2 M3 M4
precisely
– Mi has level 0 if no Mj exists
s.t. Mi r Mj
– let k be the maximum level of M1 level 2
all nodes Mj s.t. Mi r Mj. Then
Mi has level k+1
37
Discussion: USE relation
A IS-COMPONENT-OF B B COMPRISES A
B consists of several modules,
of which one is A
M M M M M M1
7 8 9 5 6
M2 M3 M4
M2 M3 M4
M M M M M
M1 They are a hierarchy 7 8 9 5 39
6
IS-COMPONENT-OF relation
M M M M M
7 8 9 5 6
M1 40
Example: OO relations
• Aggregation:
– Defines objects or object classes as composed of simpler
components that constitute the parts of other objects.
– This is a PART-OF relation (differs from IS-COMPOSED-OF)
Triangle Person
1
3
Point Heart Brain Hand
Triangle USES Point Person HAS Heart, Brain, Hand
Point IS-A-PART-OF Triangle Person IS-COMPOSED-OF Heart, Brain, Hand
Not Triangle IS-COMPOSED-OF Point 41
2.5. CALLS relation
• A allocates an instance of B
• A calls B by exception or event (not A
by other resources such as types,
functions, procedures, variables,
etc.) calls
public class className {
public void deposit(double amount)
throws RemoteException { B
// Method implementation
throw new RemoteException();
}
//Remainder of class definition
}
42
II. MODULARIZATION
TECHNIQUES
1. Module
2. Relations between modules
3. Specific techniques for design for change
43
3.1. Constant configuration
import sys
44
sys.modules[_ _name_ _] = _const( )
3.2. Conditional compilation
• Have several versions of a (part of) program in the same
source file.
• Compile the program accordingly to
– Its state at runtime
– Target platform
– Ambitious testing
– ..
• Example: C pre-processor
//...source fragment common to all versions...
#ifdef hardware-1
//...source fragment for hardware 1 ...
#endif
#ifdef hardware-2
//...source fragment for hardware 2 ...
#endif
45
3.3. Software generation
46
III. SOFTWARE
ARCHITECTURES
1. Definition
2. Common architectures
3. Domain specific architectures
47
1.1. What is software architecture ?
• Shows
– gross structure of the system to be defined
– organization of the system to be defined
• Describes
– main components of a system
– external visible properties of those components
– relationships among those components
– rationale for decomposition into its components
– constraints that must be respected by any design of the
components
• Guides
– the development of the design
48
1.2. What are 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
49
2. Common architectures
• Pipes (data flow) and filters
(operations): A component reads
streams of data on its inputs and
produces streams of data on its Pipes and filters
outputs, delivering a complete
instance of the result in a
standard order.
• Blackboard (shared data
structure): Data store can
contact and trigger actions in
components when data becomes Blackboard
available.
• Event-based control (implicit
invocation): Each component can
respond to externally generated
events from other components or
the system’s environment.
Event based control
50
3. Domain-specific architectures
• MVC architecture:
– Significant amount of user interaction
52
4. Component integration
• The CORBA (Common Object Request Broker Architecture)
Middleware
• Clients and servers connected via an Object Request Broker
(ORB)
• Interfaces provided by servers defined by an Interface
Definition Language (IDL)
• In the Microsoft world: DCOM (Distributed Component Object
Model)
CORBA Services
53
Quiz and Exercises
54
1. Which of the following statements
are true ? Why ?
A. Designing module interfaces of a software
means designing a software architecture at high
level.
B. The program structure is used as a framework
for component integration.
C. A module represents a concern where its
solution could be changed later.
D. Module interface should present the solutions
that client modules needs.
E. When a module X requires a correct
implementation of a module Y for performing its
task, it’s an USE relation.
55
2. What are the desirable properties of
a modular structure?
A. Reused, independently developed,
independently exchanged, used
B. Reused, independently developed,
independently tested, used
C. Abstraction, anticipation of change
D. Anticipation of change
56
3. Exercises
• The XYZ Wear Corporation plans to develop (from system
analysis to operation testing) the web site for selling wears
through Internet and to form the new whole system as
follow:
Member
Internet
Administration
Administration
Search
Product
Of
Selling
DB Selling, Products,
Logistics, Dealing
Order
Customer
Transportation
Operation
Customer
57
3. Exercises
58
Expected result
59
• 2. Apply the modularization techniques for
designing the online selling software. Point out
the modularization techniques that are suitable to
cope with the changes identified in the 1st in-
class assignment. Explain.
– Identify design decisions
– Identify modules
– Identify relationships between modules.
– Illustrate the interactions among modules (as figured in
the slides)
à Explain your idea by answering these questions:
• How to define the structure of this modular system?
• What are the desirable properties of that structure?
60
• 3. Point out a software architecture that is
convenient to build the online selling software.
Explain.
– Identify the architecture
– Identify the components of this architecture
– Explain the relationship between components of this
architecture
– Check the components of program structure, comparing
to that of software architecture.
61