SP02
SP02
SP02
@2012-2013
Introduction
Software engineering = problem solving activity:
Understanding the problem
Designing an algorithm as a solution
Implementing the algorithm in a computer program
Book
Part
Chapter
Section
Paragraph
Sentence
Phrase
Word
Covered topics
Control structures
Data structures
Functions and procedures
Separation of concerns
I. CONTROL STRUCTURES
1. Sequence
2. Selection
3. Repetition
5
Introduction
Computer program represents an algorithm
resolving a given problem.
All computer programs, no matter how simple or
how complex, are written using one or more of
three basic structures:
Sequence
Selection
Repetition
1. Sequence structure
The sequence structure in a computer program
directs the computer to process the statements
one after another, in the order listed in the
program
1. Sequence structure
A statement may be:
Assignment statement
Input /output statement
Composite statement
2. Selection structure
Make a decision, and then take an appropriate
action based on that decision
Provide the appropriate action to take based on
the result of that decision
The decision depends on various condition values
2. Selection structure
Single input
single output
Single input
double output
condition
Single input
multiple output
condition
TRUE
S1
TRUE
S1
value
FALSE
S2
v1
S1
vn
Sn
10
2. Selection structure
11
3. Repetition structure
Allow the programmer to specify that an action
should be repeated, depending on the condition
value
When used in a program, the repetition structure,
also referred to as a loop, directs the computer to
repeat one or more statements until some
condition is met, at which time the computer
should stop repeating the statements
12
3. Repetition structure
FALSE
S1
..
Sn
condition
TRUE
S1
..
Sn
condition
FALSE
TRUE
13
3. Repetition structure
Case 1: The repetition number is known in
advance
14
3. Repetition structure
Case 2: The repetition number is not known in advance
Statements in the body of this repetition structure are
executed repeatedly as long as the loop-continuation test is
evaluated to false
The condition is first evaluated: may be none of these statements
is executed
Otherwise, these statements are executed at least one time
15
16
Type
Primitive type:
Integer, Boolean, String,
Composite type
Tuple
Array
List
Tree
Hash
Graph
17
Pascal, .NET:
function returns value
procedure doesnt return value.
DBMS:
procedures (SPROCs) : stored compiled queries
functions (UDFs): built-in piece of expressions used to
build queries
19
IV. SEPARATION OF
CONCERNS
1.
2.
3.
4.
Principles
Concerns
Types of separation
Stakeholders of concerns
20
1. Principles
The principle of separation of concerns states that
software should be organized so that each program
element does one thing and one thing only.
Each program element should therefore be
understandable without reference to other elements.
Program abstractions (procedures, objects, etc.)
support the separation of concerns.
Procedural programming languages such as C and Pascal
can separate concerns into procedures.
Object-oriented programming languages such as Java can
separate concerns into objects.
Service-oriented architecture can separate concerns into
services.
21
2. Concerns
A concern is an area of interest or focus in a
system.
Concerns are the primary criteria for
decomposing software into smaller, more
manageable and comprehensible parts that have
meaning to a software engineer.
Procedural programming, describing concerns as
procedures
Object-oriented programming, describing concerns as
objects
22
3. Types of separation
Quality: deal separately different quality aspects
of the system
E.g.: security
23
4. Stakeholder concerns
Functional concerns: related to specific functionalities to be
included in a system
Quality of service concerns: related to the non-functional
behaviors of a system
Policy concerns: related to the overall policies that govern
the use of the system
System concerns: related to attributes of the system as a
whole, such as its maintainability or its configurability
Organizational concerns: related to organizational goals and
priorities such as:
producing a system within budget
making use of existing software assets
maintaining the reputation of an organization
24
Transfer
Deposit
Withdraw
25
Example:
Banking systems core concerns
Core concerns: functional concerns relating to the
primary purpose of a system
Transfer
Transfer
concern
Deposit
Deposit
concern
Withdraw
Withdraw
concern
26
}
fromAccount.withdraw(amount);
toAccount.deposit(amount);
}
27
Example:
Banking systems secondary concerns
Secondary concerns: functional concerns that
reflect non-functional and QoS requirements
Authentication Concern
Authentication Concern
Logging Concern
Logging Concern
Transfer
Transfer
Deposit
Deposit
concern
concern
Transaction Concern
Transaction Concern
Authentication Concern
Logging Concern
Withdraw
Withdraw
al
concern
Transaction Concern
28
}
Transaction Concern
Transaction tx = database.newTransaction();
try {
if (fromAccount.getBalance() < amount) {
throw new InsufficientFundsException();
Transfer Concern
}
fromAccount.withdraw(amount);
toAccount.deposit(amount);
Transaction Concern
tx.commit();
Logging Concern
Transaction Concern
tx.rollback();
throw e;
}
CONCLUSION
30
Data structures
Abstracted by means of operations that can be
performed on a domain of values
31
32
Discussion
What is a well structured program ?
33
Exercises
Write a well structured program that
reads a set of floating point values from the user in the
range [0, 100]
computes and prints the average,
finds and prints the maximum value,
finds and prints the minimum value,
prints the values in sorted order
Using
Sequence, selection, and repetition structures
At least 2 different programming languages
34