Download as pdf or txt
Download as pdf or txt
You are on page 1of 8

Software Design

• Process of converting the requirements into the


design of the system.

Detailed Design • Definition of how the software is to be structured or


organized.
!
!
!
• For large systems, this is divided into two parts:
- Architectural design defines main components of the system
(Chapter 7) and how they interact.
- Detailed design components are decomposed and described
at a much finer level of detail.

1 2

Design and Implementation Design Processes


• Software Design:
- Creative activity, in which you: • Functional Decomposition
- Identify software components and their relationships - aka: Top down design
- Based on requirements.
• Relational Database Design
• Implementation is the process of realizing the design
as a program. • Object-oriented design and UML
- class diagrams
• Design may be - state diagrams
- Documented in UML (or other) models - etc.
- Informal sketches (whiteboard, paper)
- In the programmer’s head. • [User Interface design]
• How detailed and formal it is depends on the process
that is in use.
3 4
Functional Decomposition: example
Functional Decomposition student registration system
• Used in structural programming • Design a system for managing course
(aka procedural programming) registration and enrollment.
- Start with a “main module”
- Repeatedly decompose into sub-modules. • Requirements specify four tasks
- add, modify and delete students from the database
- Lowest level modules can be implemented as functions.
- add, modify and delete courses from the database
• Can be used in Object-oriented design - add, modify, and delete sections for a given course
- to do initial decomposition of a system - register and drop students from a section.
- to decompose methods that are particularly hard to
implement. • Main module divided into four submodules
(students, courses, sections, registration)
• Decompose each into its tasks.
5 6

Functional Decomposition: example


student registration system Relational Database Design
• Many software systems must handle large
amounts of data
• Data is stored in tables
- row corresponds to an object or entity
- columns correspond to attributes of the entities
- (basically an array of structs)

• Structured Query Language (SQL), a set of


statements that
- create the tables
- add and modify data in the tables
- retrieve data that match specified criteria
7 8
Relational Database Design Relational Database Design

• Database design concentrates on • Data modeling: ER diagram


- how to represent the data of the system, and - Entities: rectangles
- how to store it efficiently - Attributes: ovals
- Relationships: diamonds
• Data modeling
- create a model showing the entities with their attributes, and how
the entities are related to each other
• Identifier
- attribute that has a unique value for each entity (underlined)
• Logical database design
• Multi-valued attribute
- maps the model to a set of tables - can have several values at one time (double oval)
- relationships are represented via attributes called foreign keys
- i.e. email addresses,
• Physical database design
- deciding on types of attributes, how tables are stored, etc.
9 10

Relational Database design: ER diagram


Student registration system: tables
student registration system

Course Number is a
foreign key, used to
implement the
“Belongs” relationship

Student ID is a
foreign key,
used to implement
the multi-valued
attribute

11 12
Object-oriented design 1 Requirements elicitation

• Object-oriented system is made up of interacting • Client and developers define the purpose of the
objects system:
- Maintain their own local state (private). - Develop use cases
- Provide operations over that state. - Determine functional and non-functional requirements

• Object-oriented design process involves • Major activities


- Designing classes (for objects) and their interactions. - Identifying actors.
- Identifying scenarios.
• Previous to the design phase: - Identifying use cases.
- Requirements are usually expressed using use cases
- Refining use cases.
and use case diagrams.
- Preliminary class diagrams have often been produced
Use case diagrams
during requirements analysis.

13 14

2 Object Oriented Analysis 3 System Design (architecture)

• Developers aim to produce a model of the


• Developers decompose the system into smaller
system subsystems
- Model is a class diagram
- Describing real world objects (only) !
!
!
• Goal: transform use cases to objects
• Major activities
• Major activities - Identify major components of the
- Identifying objects: entities from the real world system and their interactions (including interfaces).
❖ Look for nouns in use cases ❖ Use architectural patterns
- Drawing the class diagram, with relationships - Identify design goals (non-functional requirements)
- Drawing state diagrams as necessary - Refine the subsystem decomposition to address design goals

15 16
4 Object Design 5 Implementation

• Developers complete the object model by adding • Developers translate the class
implementation classes to the class diagram. diagram into source code.

! • Goal: map object model to code.

• Major activities • Major activities


- Interface specification: define public interface of objects - Map classes in model to classes in source language
- Reuse: - Map associations in model to collections in source language
❖ frameworks, existing libraries (code)
❖ OO languages don’t have “associations”
❖ design patterns (concepts)
❖ tricky: maintaining bidirectional associations
- Restructuring: maintainability, extensibility - Refactoring

17 18

Design characteristics and Legacy characteristics of design


metrics attributes
• Some characteristics of a good software design: • Targeted at detail design and coding level
- Consistency:
❖ ensure common terminology used across software • Halstead Complexity Metric
elements. - analyzes source code
❖ common approach to help facility - n1 = number of distinct operators
❖ common approach to error detection and diagnostic - n2 = number of distinct operands
processing - N1 = total number of operators (counting duplicates)
- Completeness: - N2 = total number of operands (counting duplicates)
All the requirements must be in the design


From these numbers, we calculate
❖ Design must include enough detail for the
developers to know what to do. - Program vocabulary: n = n1+n2
- Program length: N = N1+N2

19 20
Halstead Complexity Metric, cont. McCabe’s Cyclomatic Complexity

• Three more measurements • Basic idea: program quality is directly related to


- Volume: V = N * (Log2 n) the complexity of the control flow (branching)
- Difficulty: D = n1/2 * N2/n2
The difficulty to write or understand the program • Computed from a control flow diagram
- Effort: E = D * V - Cyclomatic complexity = E - N + 2p
A measure of actual coding time. - E = number of edges of the graph
- N = number of nodes of the graph
• Criticisms: - p = number of connected components (usually 1)
- These metrics really measure only the lexical complexity
of the source program and not the structure or the logic. • Alternate computations:
- Therefore not useful for analyzing design characteristics. - number of binary decision + 1
- number of closed regions +1

21 22

McCabe’s Cyclomatic Complexity


McCabe’s Cyclomatic Complexity
example
• Using the different computations: • What does the number mean?
- 7 edges - 6 nodes + 2*1 = 3
- 2 regions + 1 = 3 • It’s the maximum number of linearly independent
- 2 binary decisions (n2 and n4) + 1 = 3 paths through the flow diagram
- used to determine the number of test cases needed to
cover each path through the system

• The higher the number, the more risk exists (and


more testing is needed)
- 1-10 is considered low risk
- greater than 50 is considered high risk

23 24
Good Design attributes Coupling
• Main goal: Simplicity • Coupling is the number of dependencies between
- Easy to understand two subsystems.
- Easy to change
- It measures the dependencies between two subsystems.
- Easy to reuse
- Easy to test • If two subsystems are loosely coupled, they are
- Easy to code relatively independent

• How do we measure simplicity of a design? - Modifications to one of the subsystems will have little
impact on the other.
- Coupling (goal: loose coupling)
- Cohesion (goal: strong cohesion) • If two subsystems are strongly coupled, modifications
to one subsystem is likely to have impact on the other.

• Goal: subsystems should be as loosely coupled as is


reasonable.
25 26

Example: reducing the coupling of Example: reducing the coupling of


subsystems subsystems
Alternative 1: Direct access to the Database subsystem! Alternative 2: Indirect access to the Database through a Storage subsystem!

ResourceManagement

IncidentManagement
ResourceManagement

IncidentManagement MapManagement

MapManagement Storage

Added a subsystem: Storage


Database High coupling: Only one subsystem must
The subsystems are change if the interface to the
vulnerable to changes Database changes
(Assumes Storage interface Database
in the interface of the
Database subsystem does not change)
27 28
Cohesion Example: Decision tracking system
• Cohesion is the number of dependencies within a DecisionSubsystem

subsystem. Criterion
assesses
Alternative

- It measures the dependencies among classes within a * * *

subsystem.
solvableBy
• If a subsystem contains many objects that are related to DesignProblem based-on

each other and perform similar tasks, its cohesion is high. resolvedBy
SubTask


* Decision
If a subsystem contains a number of unrelated objects, its
cohesion is low.
implementedBy
ActionItem Task
• Goal: decompose system so that it leads to subsystems subtasks

with high cohesion. Low Cohesion:


Criterion, Alternative, and DesignProblem have No
- These subsystems are more likely to be reusable
relationships with SubTask, ActionItem, and Task
29 30

Alternative decomposition:
Decision tracking system Law of Demeter
RationaleSubsystem! • Good guideline for object-oriented design
Higher cohesion in each
subsystem. Criterion!
assesses!
Alternative!
• An object should send messages to only the following
But more subsystems and *! *!
- the object itself
*!
an extra interface between - the objects attributes (instance variables)
Task and Decision
DesignProblem! solvableBy! - the parameters of member functions of the object
based-on!
resolvedBy! - Any object created by this object
Decision! - Any object returned from a call to one of this objects member
PlanningSubsystem!
function
implementedBy!
SubTask! - Any object in any collection that is in one of the preceding
*! categories.

• “Only talk to your immediate neighbors”


ActionItem! Task!
subtasks!
“Don’t talk to strangers”
31 32

You might also like