Professional Documents
Culture Documents
IS236 Lecture 10
IS236 Lecture 10
STRUCTURED
DESIGN
into a wall!!!
SCENARIO
A door on the first floor
SCENARIO An impossible to use ATM machine
The small pieces of problem are solved by means of solution modules. Structured design
emphasis that these modules be well organized in order to achieve precise solution
STRUCTURED DESIGN
These modules are arranged in hierarchy.
They communicate with each other.
A good structured design always follows some rules for communication among
multiple modules, namely:
Cohesion - grouping of all functionally related elements.
Coupling - communication between different modules.
A good structured design has high cohesion and low coupling arrangements.
SOFTWAR There are two generic approaches for
software designing:
E DESIGN Top-Down Design
APPROAC
H
Bottom-up Design
First, start with a clear statement of the problem or concept – a single big idea.
Big Idea
Big Idea
II.C III.B
If any of those parts can be further broken down, then the process continues
TOP-DOWN DESIGN
Big Idea
II.C III.B
II.C.1 II.C.2
And so on…
TOP-DOWN DESIGN
The final design might look something like this organizational chart, showing the overall
structure of separate units that form a single complex entity.
An organizational chart is like an upside-down tree, with nodes representing each process.
The leaf nodes are those at the end of each branch of the tree.
TOP-DOWN DESIGN
Top-down design leads to modular
development.
Big Idea
II.C III.B
II.C.1 II.C.2
The leaf nodes represent modules that need to be developed and then recombined
to create the overall solution to the original problem
MODULAR DEVELOPMENT
Part I
II.C III.B
II.C.1 II.C.2
Reusable code makes programming easier because you only need to develop the solution to a
problem once; then you can call up that code whenever you need it.
Most computer systems are filled with layers of short programming modules that are
constantly reused in different situations
MODULAR DEVELOPMENT
Modules developed as part of one project, can be reused later as parts of other projects,
modified if necessary to fit new situations.
Over time, libraries of software modules for different tasks can be created.
39
RANGE OF COHESION
High Cohesion
Functional
Sequential
Communicational
Procedural
Temporal
Logical
Coincidental
Low
COINCIDENTAL COHESION –
LOWEST COHESION
Definition: Parts of the component are only related by their location in source code
All the above functions have no relationship but they are there in the same
module by chance!!
LOGICAL COHESION
Definition: Elements of component are related logically and not functionally.
Logical cohesion is when parts of a module are grouped because they are logically
categorized to do the same thing even though they are different by nature (e.g., grouping
all mouse and keyboard input handling routines or bundling all models, views, and controllers
in separate folders in an MVC pattern).
A logically cohesive module performs several activities of the same general category in
which the activity or activities to be executed are selected by the invoking module
EXAMPLE- I/O OPERATION
A component reads inputs from tape, disk, and network. All the code for these functions are
in the same component.
Operations are related, but the functions are significantly different.
TEMPORAL COHESION
A temporally cohesive module is one which performs several activities that
are related in time.
45
EXAMPLE
An initialization routine that initializes data used by many modules
throughout a system is a temporally cohesive module.
A function which is called after catching an exception which closes open files,
creates an error log, and notifies the user is temporally cohesive.
PROCEDURAL COHESION
Definition: Elements of a component are related only to ensure a particular
order of execution.
Parts of a module are grouped because they operate on the same data
EXAMPLE
52
FUNCTIONAL COHESION –
HIGHLY COHESIVE
Definition: Every essential element to a single computation is contained in
the component.
A functionally cohesive module performs one and only one problem related
task.
EXAMPLES
54
COUPLING
Coupling occurs when there are interdependencies between one module and
another
When interdependencies exist, changes in one place will require changes
somewhere else.
A network of interdependencies makes it difficult to see at a glance how
some component works.
Content
Common
Control
Loose
Stamp
Data
Low
CONTENT COUPLING
The Worst of the Bad!
Occurs when one component modifies data (or instructions!) that is/are
internal to another component
To reduce content coupling you should therefore encapsulate all instance
variables
declare them private
and provide get and set methods
All the components using global variables become coupled to each other
Clearly, when a value is changed, it may be very difficult to trace the source of
the change!
Each source process writes directly to global data store. Each sink process
reads directly from global data store.
DIAGRAMMATIC
REPRESENTATION
Shared Data Store
Source -1
Variable a Sink
Source -2
Read directly from
Variable a
Write directly to
Source -3 Variable a
63
CONTROL COUPLING –
MODERATE COUPLING
Definition: One module controls the internal logic of the other one through
parameters
Occurs when one procedure calls another using a ‘flag’ or ‘command’ that explicitly
controls what the second procedure does (passing a switch….)
64
EXAMPLE OF CONTROL COUPLING
The print routine of the customer billing accepts a customer data structure
(cid, cname, address, phone no, email address, NIC, cell no, passport no)
as an argument, parses it, and prints the name, address, and billing amount.
EXAMPLE-2
The print routine of the customer billing accepts a customer data structure as an argument,
parses it, and prints the name, address, and billing information.
Improvement
The print routine takes the customer name, address, and billing information as an argument
rather than taking the whole structure as input.
DATA COUPLING – LOWEST
LEVEL OF COUPLING
Data coupling occurs between two modules when data are passed by
parameters using a simple argument list and every item in the list is used.
69
EXAMPLE
70
FAN-IN AND FAN-OUT
Read the book – Page 386 -- 391
QUESTIONS?
COMING UP NEXT
Test 2: 7th Feb (16:00 – 18:00 – Two batches (45 minutes each))
QUESTIONS?
COOL Don’t forget to sign-up. Link is on LMS.
EXPERIMENT
THIS SATURDAY