Download presentation
Presentation is loading. Please wait.
1
DESIGN
2
Quick Summary What you have learnt so far?
Different kinds of software engineering methodology Waterfall model Spiral model Unified process Requirements :Use cases Traditional specification: semi-formal DFD Formal specification: Z, FSM, Petric Nets Object-oriented specification Class extraction, various diagram to present the class relationships
3
Design with formal specification
Example give a Z specification Can you write program codes for a “push_button” ?
4
Data and Actions Two aspects of a product Actions that operate on data
Data on which actions operate The two basic ways of designing a product Operation-oriented design Data-oriented design Third way Hybrid methods For example, object-oriented design that combines features of operation-oriented design and data-oriented design Recall the Data Flow Diagram (DFD), how can you design a software based on a DFD? Object-oriented design is a combination of both operation-oriented and data-oriented
5
13.1 Design and Abstraction
Classical design activities Architectural design – general and high-level Detailed design Design testing Architectural design – create modules of the software Input: Specifications document Output: Modular decomposition of the software Each module is designed Specific algorithms and data structures are selected If OOP is used then architectural design is not required, why? Because “classes” already derived during specification Detailed design – specific algorithms are selected and data structures are chosen
6
13.2 Operation-Oriented Design
If system can be presented in a DFD Data flow analysis (DFA) Can use DFA with most specification methods (Structured Systems Analysis is presented here) Key point: We have detailed action information from the DFD (ie input to and output from the product) Figure 13.1
7
Data Flow Analysis Every product transforms input into output
Determine “Point of highest abstraction of input” “Point of highest abstract of output” Point of highest abstraction of input – point at which the input loses the quality of being input and simply becomes internal data operated by the product Point of highest abstraction of output – point at which data can be identified as some form of output Figure 13.2
8
Data flow analysis Point of highest abstraction of input – point at which the input loses the quality of being input and simply becomes internal data operated by the product Example – input is a membership number the output could be a flag (valid/ not valid) and a discount % Point of highest abstraction of output – point at which data can be identified as some form of output Example – an array collecting all information ready to print out
9
Example A software to solve circuit related problems
Input: V, I, R, Z etc At point of highest abstraction: a matrix Output: the unknown V at t = 10ms Other examples based on your own experiences?
10
Data Flow Analysis (contd)
Decompose the product into three modules Input, transform, and output Repeat stepwise until each module performs a single operation: high cohesion Minor modifications may be needed to lower the coupling Cohesion – degree of interaction within a module Coupling – degree of interaction between modules Cohesion - 結合;凝聚;團結力;附著
11
Cohesion The degree of interaction within a module
Seven categories or levels of cohesion (non-linear scale) Figure 7.4
12
Coincidental Cohesion
A module has coincidental cohesion if it performs multiple, completely unrelated actions Example modules: print_next_line, reverse_string_of_characters_comprising_second_parameter, add_7_to_fifth_parameter, convert_fourth_parameter_to_ floating_point Such modules arise from rules like “Every module will consist of between 35 and 50 statements” so unrelated functions put together in order to fit the size!
13
Why Is Coincidental Cohesion So Bad?
It degrades maintainability – too many things to consider A module with coincidental cohesion is not reusable – as it is doing too many things which are difficult to find other programs using all the same features The problem is easy to fix Break the module into separate modules, each performing one task
14
Logical Cohesion A module has logical cohesion when it performs a series of related actions, one of which is selected by the calling module
15
Logical Cohesion (contd)
Example 1: function_code = 7; new_operation (op code, dummy_1, dummy_2, dummy_3); // dummy_1, dummy_2, and dummy_3 are dummy variables, // not used if function code is equal to 7 Example 2: An object performing all input and output Example 3: A module that edits insertions, deletions, and modifications of master file records
16
Why Is Logical Cohesion So Bad?
The interface is difficult to understand as there may be many irrelevant information (such as dummy variables) Code for more than one action may be intertwined Difficult to reuse
17
Why Is Logical Cohesion So Bad? (contd)
A new tape unit is installed then the new codes will be added that may be inter-twined with the part related to another printer such as section numbered 1,2,3,4,6,9,10 Figure 7.5
18
Temporal Cohesion A module has temporal cohesion when it performs a series of actions related in time Example: open_old_master_file, new_master_file, transaction_file, and print_file; initialize_sales_district_table, read_first_transaction_record, read_first_old_master_record (a.k.a. perform_initialization)
19
Why Is Temporal Cohesion So Bad?
The actions of this module are weakly related to one another, but strongly related to actions in other modules Consider sales_district_table is being initialized in that module but changing the table is via a different module When changing a data it will involve many modules some of which may be overlooked Not reusable – same reason no other software will need all the functions
20
Procedural Cohesion A module has procedural cohesion if it performs a series of actions related by the procedure to be followed by the product Example: read_part_number_and_update_repair_record_on_ master_file
21
Why Is Procedural Cohesion So Bad?
The actions are still weakly connected, so the module is not reusable
22
Communicational Cohesion
A module has communicational cohesion if it performs a series of actions related by the procedure to be followed by the product, but in addition all the actions operate on the same data Example 1: update_record_in_database_and_write_it_to_audit_trail Both working with record Example 2: calculate_new_coordinates_and_send_them_to_terminal Both working with coordinates
23
Why Is Communicational Cohesion So Bad?
Still lack of reusability
24
Functional Cohesion A module with functional cohesion performs exactly one action
25
7.2.6 Functional Cohesion Example 1: Example 2: Example 3: Example 4:
get_temperature_of_furnace Example 2: compute_orbital_of_electron Example 3: write_to_diskette Example 4: calculate_sales_commission
26
Why Is Functional Cohesion So Good?
More reusable Common functions can be reused easily Corrective maintenance is easier Fault isolation – easy to focus Fewer regression faults Easier to extend a product – add more functions
27
Informational Cohesion
A module has informational cohesion if it performs a number of actions, each with its own entry point, with independent code for each action, all performed on the same data structure
28
Why Is Informational Cohesion So Good?
Essentially, this is an abstract data type (see later)
29
Cohesion Example Figure 7.7
30
Example When two or more different levels of cohesion can be assigned to a module is to assign the lowest possible level
31
Coupling The degree of interaction between two modules
Five categories or levels of coupling (non-linear scale) Figure 7.8
32
Content Coupling Two modules are content coupled if one directly references contents of the other Example 1: Module p modifies a statement of module q Example 2: Module p refers to local data of module q in terms of some numerical displacement within q Example 3: Module p branches into a local label of module q Not so common in writing high level language programming
33
Why Is Content Coupling So Bad?
Almost any change to module q, even recompiling q with a new compiler or assembler, requires a change to module p Difficult to reuse only module p
34
Common Coupling Two modules are common coupled if they have write access to global data Example 1 Modules cca and ccb can access and change the value of global_variable Figure 7.9
35
Common Coupling Example 2:
Modules cca and ccb both have access to the same database, and can both read and write the same record Example 3: FORTRAN common COBOL common (nonstandard) COBOL-80 global
36
Why Is Common Coupling So Bad?
It contradicts the spirit of structured programming The resulting code is virtually unreadable What causes this loop to terminate if global_variable is a global variable As its value can be changed with many possibilities Figure 7.10
37
Why Is Common Coupling So Bad? (contd)
Modules can have side-effects This affects their readability Example: edit_this_transaction (record_7) The entire module source must be read to find out what it does because other global variables (not just record_7) may be changed by the function A change during maintenance to the declaration of a global variable in one module necessitates corresponding changes in other modules Common-coupled modules are difficult to reuse because global variables are missing in the new software system
38
Why Is Common Coupling So Bad? (contd)
Common coupling between a module p and the rest of the product can change without changing p in any way For example, if both module p and q can modify global variable gv then there is one instance of common coupling between p and the other modules. But if 10 new modules are designed and implemented, all of which can modify global variable gv, then the number of instances of common coupling between module p and the other modules increases to 11 A module is exposed to more data than necessary This can lead to computer crime as control of data access is reduced
39
Control Coupling Two modules are control coupled if one passes an element of control to the other Example 1: An operation code is passed to a module with logical cohesion Example 2: A control switch passed as an argument
40
Control Coupling (contd)
Module p calls module q Message: I have failed (a flag) — data I have failed, so write error message ABC123 — control The return by q is controlling the action of p (ie to display the corresponding error message)
41
Why Is Control Coupling So Bad?
The modules are not independent Module q (the called module) must know the internal structure and logic of module p otherwise cannot pass back the proper control This affects reusability Modules are usually logical cohesion
42
Stamp Coupling Some languages allow only simple variables as parameters part_number satellite_altitude degree_of_multiprogramming Many languages also support the passing of data structures part_record satellite_coordinates segment_table
43
Stamp Coupling (contd)
Two modules are stamp coupled if a data structure is passed as a parameter, but the called module operates on some but not all of the individual components of the data structure
44
Why Is Stamp Coupling So Bad?
It is not clear, without reading the entire module, which fields of a record (employee_record) are accessed or changed Example calculate_withholding (employee_record) Difficult to understand Unlikely to be reusable More data than necessary is passed Uncontrolled data access can lead to computer crime
45
Why Is Stamp Coupling So Bad? (contd)
However, there is nothing wrong with passing a data structure as a parameter, provided that all the components of the data structure are accessed and/or changed Examples: invert_matrix (original_matrix, inverted_matrix); print_inventory_record (warehouse_record);
46
Data Coupling Two modules are data coupled if all parameters are homogeneous data items (simple parameters, or data structures all of whose elements are used by called module) Examples: display_time_of_arrival (flight_number); compute_product (first_number, second_number); get_job_with_highest_priority (job_queue);
47
Why Is Data Coupling So Good?
The difficulties of content, common, control, and stamp coupling are not present Maintenance is easier because a change in one module is less likely to cause a regression fault in the other
48
Coupling Example The number in the link is the interface
P calls q with interface (1) Figure 7.11
49
Coupling Example (contd)
Figure 7.12 Interface description
50
Coupling Example (contd)
Figure 7.13 Coupling between all pairs of modules
51
Mini Case Study: Word Counting
Example: Design a product which takes as input a file name, and returns the number of words in that file (like UNIX wc ) Figure 13.3 From programming point of view A file pointer is used to present the file
52
Mini Case Study: Word Counting (contd)
First refinement – represented using structured diagram Now refine the two modules of communicational cohesion Read_and_validate_file_name shows a communicational cohesion it performs a series of operations related by the sequence of steps In the structured diagram (SD), each node represent a module. A module is a functional abstraction to be implemented by a software module Usually assume a modules are called by a master module (transaction flow centered) SD is derived from the DFD Communication cohesion – a series of operations related by the sequence of steps to be followed by the product and if all the operations are performed on the same data
53
Structure diagram In the structured diagram (SD), each node represent a module. A module is a functional abstraction to be implemented by a software module Usually assume a modules are called by a master module (transaction flow centered) SD is derived from the DFD
54
Mini Case Study: Word Counting (contd)
Second refinement All eight modules now have functional cohesion Functional cohesion – a module that performs exactly one operation or achieves a single goal Figure 13.5
55
Word Counting: Detailed Design
The architectural design is complete So proceed to the detailed design Data structures are chosen Algorithms selected The detailed design is handed to a programmer for implementation Two formats for representing the detailed design: Tabular Pseudocode (PDL — program design language) PDL is usually used if the programming language is chosen
56
Detailed Design: Tabular Format
Figure 13.6(a)
57
Detailed Design: Tabular Format (contd)
Figure 13.6(b)
58
Detailed Design: Tabular Format (contd)
Figure 13.6(c)
59
Detailed Design: Tabular Format (contd)
Figure 13.6(d)
60
Detailed Design: PDL Format
The structure of the above PDL is similar to the C/C++ or Java languages Converting the comments into program codes then the program is done Figure 13.7
61
13.3.2 Data Flow Analysis Extensions
In real-world products, there is More than one input stream, and More than one output stream
62
Data Flow Analysis Extensions
Find the point of highest abstraction for each stream Continue until each module has high cohesion Adjust the coupling if needed Figure 13.8
63
Exercise Based on the DFD of the library system, design the circulation system using data flow analysis Draw the structured diagram (2 iterations) Detailed design of “obtained_catalog_information” PDL for “check_out_book”
64
Exercise Convert the above Z specification into a PDL
65
Data-Oriented Design Basic principle
Design the product according to the structure of the data on which it is to operate Each procedure is given the same structure as the data on which it operates Three very similar methods Michael Jackson [1975], Warnier [1976], Orr [1981] Data-oriented design Has never been as popular as action-oriented design With the rise of OOD, data-oriented design has largely fallen out of fashion Not very popular
66
13.6 Object-Oriented Design (OOD)
Aim Design the product in terms of the classes extracted during OOA If we are using a language without inheritance (e.g., C, Ada 83) Use abstract data type design If we are using a language without a type statement (e.g., FORTRAN, COBOL) Use data encapsulation OOD – can be adopted by other non-OOP languages Abstract data type and data encapsulation are two major features of OOD
67
Object-Oriented Design Steps
OOD consists of two steps: Step 1. Complete the class diagram Determine the formats of the attributes Assign each method, either to a class or to a client that sends a message to an object of that class Step 2. Perform the detailed design
68
Object-Oriented Design Steps (contd)
Step 1. Complete the class diagram The formats of the attributes can be directly deduced from the analysis artifacts Example of deriving an attribute: Dates U.S. format (mm/mm/yyyy) European format (dd/mm/yyyy) In both instances, 10 characters are needed
69
Object-Oriented Design Steps (contd)
Step 1. Complete the class diagram Assign each method, either to a class or to a client that sends a message to an object of that class Principle A: Information hiding Principle B: If an operation is invoked by many clients of an object, assign the method to the object, not the clients Principle C: Responsibility-driven design (class receiving the request is responsible to carry out the operation) Information hiding – a class can have state variables declared as private or protected. Operations performed on state variables must be local to that class (information of the variable is hidden from the outside)
70
Information hiding An object is a collection of data and function so entities outside an object does not know what is inside (information is hidden from the outside world!!!)
71
13.7 Object-Oriented Design: The Elevator Problem Case Study
Step 1. Complete the class diagram Need to identify methods (functions) of a class Consider the second iteration of the CRC card for the elevator controller
72
OOD: Elevator Problem Case Study
CRC card Figure 12.9 (again)
73
OOD: Elevator Problem Case Study (contd)
Responsibilities 8. Start timer 10. Check requests, and 11. Update requests are assigned to the elevator controller Because they are carried out by the elevator controller – according to responsibility-driven design
74
OOD: Elevator Problem Case Study (contd)
The remaining eight responsibilities have the form “Send a message to another class to tell it do something” These should be assigned to that other class Responsibility-driven design Safety considerations Methods open doors, close doors are assigned to class Elevator Doors Class Methods turn off button, turn on button are assigned to classes Floor Button Class and Elevator Problem Class
75
Detailed Class Diagram: Elevator Problem
Figure 13.11
76
Detailed Design: Elevator Problem
Detailed design of elevatorEventLoop is constructed from the statechart Figure 13.12
77
Dynamic Modeling: The Elevator Problem Case Study
Produce a UML statechart State, event, and predicate are distributed over the statechart Aim of dynamic modeling is to produce the state chart State chart provides a description of the target product similar to a finite state machine for each class The above is the state chart for the elevator controller class only!! Elevator event loop, going into wait state etc are states Elevator stopped no requests pending – event Close elevator doors after timeout – operation to be carried out when the state “Going into wait state” has been entered Figure 12.7
78
13.8 Object-Oriented Design: The MSG Foundation Case Study
Step 1. Complete the class diagram The final class diagram is shown in the next slide Date Class is needed for C++ Java has built-it functions for handling dates
79
Final Class Diagram: MSG Foundation
Figure 13.13
80
Class Diagram with Attributes: MSG Foundation
Figure 13.14
81
Assigning Methods to Classes: MSG Foundation
Example: setAssetNumber, getAssetNumber From the inheritance tree, these accessor/mutator methods should be assigned to Asset Class So that they can be inherited by both subclasses of Asset Class (Investment Class and Mortgage Class) Accessor – function to obtain attribute of a class Mutator – function that modify attribute of a class Figure 13.15
82
Assigning Methods to Classes: MSG Foundation
83
Detailed Design: MSG Foundation
Determine what each method does Represent the detailed design in an appropriate format PDL (pseudocode) here
84
Method EstimateFundsForWeek::computeEstimatedFunds
Figure 13.16
85
Method Mortgage::totalWeeklyNetPayments
Figure 13.17
86
13.9 The Design Workflow Summary of the design workflow:
The analysis workflow documents (input for design workflow) are iterated and integrated until the programmers can utilize them Major tasks to achieve – identify the methods to be assigned to classes as well as performing detailed design Decisions to be made include: What programming language to use Reuse of existing software components Portability – work under different software/hardware platform
87
The Design Workflow (contd)
The idea of decomposing a large workflow into independent smaller workflows (packages) is carried forward to the design workflow The objective is to break up the upcoming implementation workflow into manageable pieces Subsystems It does not make sense to break up the MSG Foundation case study into subsystems — it is too small Package – a term used in C++ or other OOP languages to describe a concept similar to a library
88
The Design Workflow (contd)
Why the product is broken into subsystems: It is easier to implement a number of smaller subsystems than one large system If the subsystems are independent, they can be implemented by programming teams working in parallel The software product as a whole can then be delivered sooner
89
The Design Workflow (contd)
The architecture of a software product includes The various components How they fit together The allocation of components to subsystems The task of designing the architecture is specialized It is performed by a software architect
90
The Design Workflow (contd)
The architect needs to make trade-offs Every software product must satisfy its functional requirements (the use cases) It also must satisfy its nonfunctional requirements, including Portability, reliability, robustness, maintainability, and security It must do all these things within budget and time constraints The architect must assist the client by laying out the trade-offs – balance between the requirements and the budget
91
The Design Workflow (contd)
It is usually impossible to satisfy all the requirements, functional and nonfunctional, within the cost and time constraints Some sort of compromises have to be made The client has to Relax some of the requirements; Increase the budget; and/or Move the delivery deadline The software architect must provide expert knowledge to assist the client to make the proper decision !!!!
92
The Design Workflow (contd)
The architecture of a software product is critical The requirements workflow can be fixed during the analysis workflow The analysis workflow can be fixed during the design workflow The design workflow can be fixed during the implementation workflow But there is no way to recover from a suboptimal architecture The architecture must immediately be redesigned
93
13.10 The Test Workflow: Design
Testing the design Design reviews (testing) must be performed The design must correctly reflect the specifications The design itself must be correct
94
13.11 The Test Workflow: The MSG Foundation Case Study
A design inspection must be performed All aspects of the design must be checked Even if no faults are found, the design may be changed during the implementation workflow
95
13.12 Formal Techniques for Detailed Design
Implementing a complete product and then proving it correct is hard However, use of formal techniques during detailed design can help Correctness proving can be applied to module-sized pieces The design should have fewer faults if it is developed in parallel with a correctness proof If the same programmer does the detailed design and implementation The programmer will have a positive attitude to the detailed design This should lead to fewer faults Assume developing the proof and the detailed design in parallel
96
13.15 Metrics for Design Measures of design quality Cohesion Coupling
Fault statistics Cyclomatic complexity (M) – counting the number of binary decisions (branches) plus 1; the lower the value of M, the better CC = 1 if no decision is made Cyclomatic complexity is problematic Data complexity is ignored (the value M is related to the control complexity) It is not used much with the object-oriented paradigm
97
Cyclomatic Complexity
What is the cyclomatic complexity for the flow graph?
98
Metrics for Design (contd)
Metrics have been put forward for the object-oriented paradigm They have been challenged on both theoretical and experimental grounds There is no suitable metric for OOD
99
13.16 Challenges of the Design Phase
The design team should not do too much The detailed design should not become code The design team should not do too little It is essential for the design team to produce a complete detailed design
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.