Software Engineering: Analysis and Design CSE3308

1 / 42
About This Presentation
Title:

Software Engineering: Analysis and Design CSE3308

Description:

Structured Design is only concerned with the outside view of the module ... A module is defined as a collection of program statements with four attributes: ... – PowerPoint PPT presentation

Number of Views:34
Avg rating:3.0/5.0
Slides: 43
Provided by: DavidSquir

less

Transcript and Presenter's Notes

Title: Software Engineering: Analysis and Design CSE3308


1
Software Engineering Analysis and Design -
CSE3308
CSE3308/DMS/2001/7
Monash University - School of Computer Science
and Software Engineering
  • Structured Design

2
Lecture Outline
  • The Structure Chart
  • Qualities of Good Design
  • Coupling
  • Cohesion
  • Factoring
  • Fan-out
  • Fan-in
  • Transform Analysis

3
The Structure Chart - 1
  • Principal tool of Structured Design
  • Based on dividing a system into modules à la
    Structured Programming and then mapping the
    connections between the modules
  • Structured Design is only concerned with the
    outside view of the module

4
The Structure Chart - 2
  • A module is defined as a collection of program
    statements with four attributes
  • input and output - what the module gets from its
    invoker and what the invoker receives from the
    module
  • function - what it does to its input to produce
    its output
  • mechanics - the code or logic by which it carries
    out its function
  • internal data - its own private workspace, data
    to which it alone refers

5
Connections between modules
  • A connection indicates that one module calls
    another module

A
Get Customer Details
Calling Module
B
Find Customer Name
Called Module
6
Showing Data and Information
  • Need to show the movement of data and the
    movement of information about data (flags)

Get Customer Details
Flag going from caller to called
Data going from caller to called
Customer Name
Customer Account Number
Flag going from called to caller
Account Number is OK
Data going from called to caller
Find Customer Name
7
Difference between Data and Flags
  • Data is processed, flags are not
  • A flag is typically set and tested
  • Data relates to the problem
  • Flags communicate information about the data

8
Iteration and Decision on a Structure Chart
Symbol for showing decisions
Symbol for showing iteration
Issue pay cheques for all employees
Calculate Pay for Salaried Worker
Calculate Pay for Casual Worker
Get Employee Pay Record
Print Pay Cheque
9
Example Structure Chart
SUMMARIZE PAYMENTS FOR ALL CUSTOMERS
Total for One Customer
Total for All Customers
Total for One Customer
EOTP
PUT CUSTOMER TOTAL
PUT FINAL TOTAL
GET TOTAL PAYMENT FOR ONE CUSTOMER
Valid Customer Record
EOVCR
Final Total Line
Customer Total Line
GET VALID CUSTOMER RECORD
Field Valid
Customer Record
Field
EDIT FIELD
10
Exercise - Enrol Students
  • 4 main modules for Enrol Students
  • Confirm Student Details (needs Student ID)
  • Determine Subjects (needs Student ID)
  • Calculate Fees (has two sub-modules)
  • Calculate HECS Fee (needs Subject Details)
  • Calculate Amenities Fee (needs Student ID)
  • Print Fee Advice (needs Total Fees)

11
Your Answer
12
Coupling
  • Coupling indicates the degree of interdependence
    between two modules
  • Aim for low coupling by
  • eliminating unnecessary relationships
  • reducing the number of necessary relationships
  • easing the tightness of necessary relationships
  • Example of low coupling
  • Stereo System

13
Advantages of Loose Coupling
  • The fewer connections between modules, the less
    chance of a defect in one causing a defect in
    another
  • The risk of having to change other modules as a
    result of changing one module is reduced
  • The need to know about the internals of other
    modules is reduced when maintaining the details
    of other modules.
  • But of course we have to have some coupling!

14
Principles of Coupling
  • Narrow is better than Broad
  • Direct is better than Indirect
  • Local is better than Remote
  • Obvious is better than Obscure
  • Flexible is better than Rigid

15
Types of Coupling
  • Data Coupling
  • Stamp Coupling
  • Control Coupling

Good Coupling
  • Common Coupling
  • Content Coupling
  • Hybrid Coupling

Bad Coupling
16
Data Coupling
  • Two modules are data coupled if they communicate
    via parameters, each parameter being an
    elementary piece of data
  • Data coupling is necessary in a program and is
    harmless if kept to a minimum
  • Avoid tramp data which moves around the structure
    chart aimlessly

Assess House Affordability
Term
Interest rate
Repayment rate
Sum borrowed
Calculate Mortgage Repayment
17
Tramp Data Example
18
Stamp Coupling
  • Stamp coupling is where one module passes to
    another a composite piece of data, i.e. a piece
    of data with meaningful internal structure
  • Stamp coupling results in some indirectness,
    therefore not as desirable, but okay if the
    composite is natural to the application
  • Never pass composite data when only part of the
    data is required
  • Never bundle data into an artificial composite

19
Stamp Coupling Examples
Bad
Good
Play Chess
Generate Customer Rental Bill
Customer Rental Record
Move
Customer Rental Record
New Chess Board
Basic Rental Charge
Gasoline Charge
Chess Board
Calculate Basic Rental Charge
Calculate Gasoline Charge
Make Move
20
Bundling
Number of items
Price per item
Purchase data
Total cost
Total cost
Sales tax
Discount type
Calculate Total Purchase Cost
Calculate Total Purchase Cost
21
Control Coupling
  • Control coupling is when one module passes to
    another a piece of information intended to
    control the internal logic of the other
  • Generally not a good thing!
  • Poor partitioning
  • Inversion of authority
  • However flags which are descriptive can be fine
  • Account Number is invalid
  • End of file has been reached

Match Customer Records
Master Record
What to do flag
Transaction Record
System I/O Control
22
Summary of Acceptable Coupling
23
Coupling Evils - Common Coupling
  • Two modules are common coupled if they both refer
    to the same global data area
  • defect in a common coupled module may show up
    anywhere
  • common coupling is usually by a specific name,
    therefore reduces flexibility
  • remoteness in time between the coupling
  • easy to abuse by using the same data item for
    different meanings in different modules
  • very hard to maintain and understand due to
    difficulty in working out the actual coupling
  • difficult to work out what modules must be
    changed if data is changed and vice versa

24
Coupling Evils - Content Coupling and Hybrid
Coupling
  • Content coupling is where one module refers to
    the inside of another in any way
  • one module changes the data inside another
  • one module alters a statement in another
  • Defies the principle of modularity
  • Hybrid coupling is where different meanings are
    assigned to different parts of a range of data,
    it is both a data flag and a control flag
    simultaneously

25
Hybrid Coupling Example
Special 90XXX Range means mail literature to
whole region represented by last three digits
91000
99999
91999
00001
Account Number
90000
90999
Normal Range
Special 91XXX Range means Extra Credit Period
26
Impact of coupling
Depends on the breadth (the number of
individual items) of the interface If the
convention used in the hybrid data has to be
changed, ripple effect can be devastating
poor mainly because of problems in interface and
cohesion of one of the modules
27
Cohesion
  • Is the measure of the strength of functional
    relatedness of elements within a module
  • Element means
  • an instruction
  • a group of instructions
  • a data definition
  • a call to another module
  • i.e. any piece of code that accomplishes some
    work or defines some data
  • We want strong cohesion modules whose elements
    are functionally related
  • Measure of how well we have partitioned the system

28
Types of Cohesion
Maintainability
  • Functional
  • Sequential
  • Communicational
  • Procedural
  • Temporal
  • Logical
  • Coincidental
  • Black Box
  • Not quite as Black Box
  • Not quite as Black Box
  • Grey Box
  • Grey Box
  • White Box
  • White Box

29
Functional Cohesion
  • Where a module contains elements that all
    contribute to the execution of one and only one
    problem related task
  • Examples
  • Compute Cosine of Angle
  • Read Transaction Record
  • Calculate Net Salary
  • Assign Seat to Airline Customer
  • Best type of cohesion, but not all modules can be
    defined as performing one function

30
Sequential Cohesion
  • Where a module has elements which are involved in
    activities such that output data from one
    activity serves as input data to the next
  • Example
  • Usually has good coupling
  • Easily maintained
  • Not as reusable

Formatted Cross-Validated Record
Raw Record
Format and Cross- Validate Record
31
Communicational Cohesion
  • Where a module has elements that contribute to
    activities that use the same input or output data
  • Example

module determine customer details use customer
account number find customer name find customer
loan balance return customer name, customer loan
balance endmodule
  • Are quite maintainable but problems include
  • Unnecessary data when reusing
  • Temptation to share code among the activities in
    the modules making it difficult to change one and
    not the other

32
Problem with Communicational Cohesion
Employee Salary Table
Average Salary
Customer Account Number
Customer Name
Produce Employee Salary Report and Calculate
Average Salary
Customer Name
Find Customer Name
Customer Account Number
Customer Loan Balance
Employee Salary Report Details
AND
Determine Customer Details
Customer Account Number
Customer Loan Balance
should become
Write
Calculate Customer Loan Balance
33
Procedural Cohesion
  • Where a module has elements that are involved in
    different and possible unrelated activities in
    which control flows from one activity to the next
  • Example

Table A Average
  • Procedure is the same for the different data
  • Data is unrelated
  • Maintenance can become very complex - i.e. what
    happens if size of one table changes?

Table A
Table B Average
Table B
Compute Table A Average and Table B Average
34
Temporal Cohesion
  • Where a module has elements which are involved in
    activities that are related in time
  • Example - Get Ready for Bed Module
  • Put out garbage can
  • Put out cat
  • Turn off TV
  • Brush teeth
  • Activities are unrelated except for being carried
    out at a particular time.
  • Classic example is an Initialisation module
  • Does not lead to good maintainability

35
Logical Cohesion
  • Where a module has elements which contribute to
    activities of the same general category in which
    the activity or activities to be executed are
    selected from outside the module
  • Example

Destination
Arrival Flag
module travel to new destination uses
destination, travel type flag if travel type
flag BUS go destination by BUS if travel
type flag TRAIN go destination by TRAIN if
travel type flag CAR go destination by CAR
return arrival flag endmodule
Travel Type Flag
Travel to New Destination
36
Problems with Logical Cohesion
  • Code of different activities is knotted together
  • Example

All the records have different character
lengths when INPUT-FLAG 1 RECORD-A is written
to NEW MASTER FILE RECORD-B is set to next TRAN
FILE1 record RECORD-C is undefined when
INPUT-FLAG 2 RECORD-A is used as an auxiliary
input flag RECORD-B is set to next TRAN FILE1
record (only if RECORD-A set to
SPACES otherwise undefined RECORD-C is set to
the next TRAN FILE2 record when INPUT-FLAG
3 RECORD-A is set to the next MASTER FILE2
record RECORD-B is set to next TRAN FILE1 record
RECORD-C is set to the next MASTER FILE2 record
37
Coincidental Cohesion
  • Where the elements of a module have no meaningful
    relationship to each other
  • Elements are not related by flow of data or flow
    of control

Account
Transaction Record
Matnum
Account
Operator Message
Error Flag
Func flag
Miscellaneous Functions
38
Impact of cohesion
39
Results of Cohesion
40
Factoring
  • The separation of a function contained as code
    into a new module of its own
  • Reasons
  • to reduce module size
  • to aid in the understanding of the system and to
    make modifications more localised
  • to avoid duplication of a function in more than
    one module
  • to separate work (calculating and editing) from
    management (calling and deciding)
  • to provide more reusable modules
  • to simplify implementation

41
Fan-Out and Fan-In
  • Fan-out the number of immediate subordinates to
    a module
  • limit fan-out to no more than seven
  • Fan-in the number of immediate bosses that a
    module has
  • Is a good thing - indicates reuse
  • Modules with fan-in must have good cohesion,
    preferably functional
  • each interface to the module must have the same
    number and types of parameters

42
Transform Analysis
  • Method for converting DFDs into Structure chart
  • Analyse the DFDs in terms of transactions
  • For each transaction, identify the central DFD
    process (called the central transform)
  • Central transform is the portion of the DFD that
    contains the essential functions of the system
    and is independent of the implementation of the
    input and output
  • Make the central transform the top level module
    in structure chart
Write a Comment
User Comments (0)