SE3318 - Week 4
SE3318 - Week 4
SE3318
SPRING 2024-2025
Design in Construction
Specifications in Construction
DESIGN IN CONSTRUCTION
DESIGN IN CONSTRUCTION
Design Challenges
Key Design Concepts
Design Building Blocks
Heuristics
DESIGN CHALLENGES: WHAT IS DESIGN?
1. The system
2. Organization into subsystems.
3. The subsystems are further divided
into classes.
4. The classes are divided into routines
and data.
5. The inside of each routine is also
designed
LEVEL OF DETAIL: LEVEL 1: SOFTWARE SYSTEM
Business rules High level restrictions and rules that govern the
business system.
User interface A subsystem to isolate user-interface components so
that the user interface can evolve without damaging the rest of the
program.
Database access Centralize database operations in one place and
reduce the chance of errors in working with the data.
System dependencies Package operating-system dependencies into
a subsystem for the same reason you package hardware
dependencies.
LEVEL OF DETAIL: LEVEL 4: DIVISION INTO ROUTINES
Writing pseudocode.
Looking up algorithms in reference books.
Organize source code.
SPECIFICATIONS IN CONSTRUCTION
SPECIFICATIONS IN CONSTRUCTION: WHY SPECIFICATIONS?
Requires:
val to occur exactly once in arr
Effects:
Returns index i such that
arr[i]=val
static int find(int[] arr, int val)
_requires_: val occurs exactly once in arr
_effects_: returns index i such that arr[i] = val
SPECIFICATIONS IN CONSTRUCTION: SPECIFICATION STRUCTURE
This specification allows multiple valid outputs for the same input!
Both find First and find Last satisfy the specification, but
returned index is for which one?
/**
* Find a value in an array.
* @param arr array to search, requires that val occurs exactly once
* in arr
* @param val value to search for
* @return index i such that arr[i] = val
*/
static int find(int[] arr, int val)
Coherent
Informative
Strong Enough
Weak Enough
Should use Abstract Types
GOOD SPECIFICATIONS: COHERENT
Finding in two arrays and summing the indexes are not really
related. Better to split into two methods.
GOOD SPECIFICATIONS: COHERENT
/**
* Update longestWord to be the longest element of words, and print
* the number of elements with length > LONG_WORD_LENGTH to the console.
* @param words list to search for long words
*/
public static void countLongWords(List<String> words)
Not coherent as well. It does two different things, even use global
variables... Should have been split into two different methods.
GOOD SPECIFICATIONS: INFORMATIVE
static V put (Map<K,V> map, K key, V val)
_requires_: val may be null, and map may contain null values
_effects_: inserts (key, val) into the mapping,
overriding any existing mapping for key, and
returns old value for key, unless none,
in which case it returns null
The precondition does not rule out null values so the map can
store null's.
The postcondition uses null as a special return value for a missing
key.
If null is returned, one can’t tell whether the key was not bound
previously, or whether it was in fact bound to null.
This is not a very good design, because the return value is useless unless
you know for sure that you didn’t insert null's.
GOOD SPECIFICATIONS: STRONG ENOUGH