NCCUCS 軟工概論 Software Design: Modules (KWIC case study)

Slides:



Advertisements
Similar presentations
COMPSCI 105 S Principles of Computer Science 12 Abstract Data Type.
Advertisements

Design The goal is to design a modular solution, using the techniques of: Decomposition Abstraction Encapsulation In Object Oriented Programming this is.
Week 8 Implementation Design Alex Baker. Implementation Design System Design – Describes what the system should do Implementation Design – Describes what.
IEG 3080 Tutorial 1 Wilson Ip. Outline Lecture reviews: Some basics of Software Engineering principle Some basics of OOP How to use Visual Studio.NET.
Ch4: Software Architecture and Design. 1 Modules: Interface vs. Implementation (contd..)  Interface design considerations:
Architectural styles and Case studies 1 | Website for Students | VTU NOTES | QUESTION PAPERS | NEWS | RESULTS.
On the Criteria to Be Used in Decomposing Systems into Modules Group 1: Lisa Anthony, Erik Hayes, Luiza Helena da Silva, and Diana Tetelman.
C++ fundamentals.
03 - ParnasCSC4071 A Sketchy Evolution of Software Design 1960s –Structured Programming (“Goto Considered Harmful”, E.W.Dijkstra) Emerged from considerations.
Introduction SWE 619. Why Is Building Good Software Hard? Large software systems enormously complex  Millions of “moving parts” People expect software.
Copyright © 2002, Systems and Computer Engineering, Carleton University Intro.ppt * Object-Oriented Software Development Unit 1 Course.
KWIC Project – Part 1 Mini-Project to Evaluate Architectural Patterns(Styles) Carl Chesser Ji Li EECS 761.
Design Patterns OOD. Course topics Design Principles UML –Class Diagrams –Sequence Diagrams Design Patterns C#,.NET (all the course examples) Design Principles.
1 CMPT 275 High Level Design Phase Architecture. Janice Regan, Objectives of Design  The design phase takes the results of the requirements analysis.
1 On the Criteria To Be Used in Decomposing Systems into Modules by D.L.Parnas Dec presented by Yuanhua Qu for spring 2003 CS5391.
CSE 303 – Software Design and Architecture
On the Criteria to Be Used in Decomposing Systems into Modules Team 3 Nupur Choudhary Aparna Nanjappa Mark Zeits.
ECE450 - Software Engineering II1 ECE450 – Software Engineering II Today: Key Principles of Software Architecture and Design (I) adapted from Dave Penny’s.
CSE 219 Computer Science III Program Design Principles.
SE: CHAPTER 7 Writing The Program
INF 212 Modularity Instructors: Crista Lopes Copyright © Instructors.
Design.ppt1 Top-down designs: 1. Define the Problem IPO 2. Identify tasks, Modularize 3. Use structure chart 4. Pseudocode for Mainline 5. Construct pseudocode.
Software Engineering Principles. SE Principles Principles are statements describing desirable properties of the product and process.
SOFTWARE DESIGN. INTRODUCTION There are 3 distinct types of activities in design 1.External design 2.Architectural design 3.Detailed design Architectural.
Abstraction ADTs, Information Hiding and Encapsulation.
© 2006 Pearson Addison-Wesley. All rights reserved2-1 Chapter 2 Principles of Programming & Software Engineering.
© 2006 Pearson Addison-Wesley. All rights reserved 2-1 Chapter 2 Principles of Programming & Software Engineering.
“Architecture” The outcome of top-level design, reflecting principal design decisions Can (and should) be modified and updated Analogous to architecture.
Comparing Designs By Chris McCall. Comparing Designs A decision-making method for deciding between many designs for a single specification Provides a.
1 COS 260 DAY 12 Tony Gauvin. 2 Agenda Questions? 5 th Mini quiz –Chapter 5 40 min Assignment 3 Due Assignment 4 will be posted later (next week) –If.
Lecture VIII: Software Architecture
ECE450 - Software Engineering II1 ECE450 – Software Engineering II Today: Key Principles of Software Architecture and Design (II) adapted from Dave Penny’s.
Keyword In Context Presented by Team 2 Francisco Soria Zhiyu Zhang Xuheng Xu Irene Peysakhov.
KWIC example The KWIC [key word in context] system accepts an ordered set of lines; each line is an ordered set of words, and each word is an ordered set.
CS 265 Jianbo Zhao. What is interface? Interface is a detailed boundary between code that provides a service and code that uses it. An interface defines.
Principles of Programming & Software Engineering
7. Modular and structured design
CompSci 280 S Introduction to Software Development
Data Abstraction: The Walls
Algorithms and Problem Solving
CS 325: Software Engineering
Coupling and Cohesion 1.
On the Criteria to Be Used in Decomposing Systems into Modules
Data Abstraction: The Walls
Software Design Mr. Manoj Kumar Kar.
Tutorial on BoxScript: A Component-Oriented Language
Part 3 Design What does design mean in different fields?
About the Presentations
Prepared by Charlie Meyer, May 2009
Stack ADT & Modularity 2 implementations of the Stack abstract data type: Array Linked List Program design: modularity, abstraction and information hiding.
CYBERMINER WEB SEARCH ENGINE
Subprograms and Programmer Defined Data Type
Higher-Level Testing and Integration Testing
Component-Level Design
Software Design CMSC 345, Version 1/11.
CSE 403: Notkin #2 of 3 on software change
On the Criteria To Be Used in Decomposing Systems into Modules D. L
CSE403 Software Engineering Autumn 2000 Design (Overview)
Software Design Lecture : 9.
Software Design Lecture : 8
An Introduction to Software Architecture
Algorithms and Problem Solving
Introduction to Data Structure
Paper by D.L Parnas And D.P.Siewiorek Prepared by Xi Chen May 16,2003
CyberMiner Software Architecture Group
CS 2704 Object Oriented Software Design and Construction
Software Design Lecture : 39.
Chapter 6: Architectural Design
CS/SE ADVANCED SOFTWARE ARCHITECTURE AND DESIGN FALL 2015
Module Structure David Parnas Discusses “modularization”
Presentation transcript:

NCCUCS 軟工概論 Software Design: Modules (KWIC case study) Prof. Chen, Kung April 21, 2014

Agenda Assignment 2: Graph ADT Modularity Decomposing into Modules Interface and Implementtaion Coupling and Cohesion Decomposing into Modules The KWIC Example

Assignment 2: the Graph ADT Problems Text answers Java code

Assignment 2: the Graph ADT and Path Finder MapQuick represents street connectivity with a directed graph. Streets as Nodes Interconnections as Edges Path finder: shorted path Testing driver Test scripts JUnit

Assignment 2: Sample I/O Testing Driver Test script Output

Given Code Skeleton

Your Repo to Submit 文字檔答案與程式碼,測試案例 Problem 2: c, d 不必寫 Reflection: c不必寫

Assignment 2 仔細閱讀題目,全部先都瀏覽一遍,再開始寫 有少數內容我們沒教,可略過 作答: Graph class API: specification and implementation Test cases and test scripts Description of your work and thoughts Java code 加 “某某某ps3readme.txt” 說明一下你上傳的檔案

Testing Part to Handin

Modularization (模組化): Decomposing a System into modules Tackling Design Complexity Modularization (模組化): Decomposing a System into modules

Tackling Design Complexity How: Divide-and-Conquer But how to divide? What modules? 疱丁解牛?

The most important principle in (software) engineering Separation of Interface and Implementation Abstraction:

Interface – so that parts can be changed independently Body Head Interface Front Leg Read Leg

Properties of Modularization What are good modularization? Properties of Modularization Cohesion and Coupling

Bad modularization 糾結在一起,不好切割 Tight Coupling

How Worse It Could Be! 牽一髮而動全身

Good Modularization Rule of Modularity: Write simple parts connected by clean interfaces.

Good Modularization 好分工

Modularity: Simple Parts Cohesion: “The measure of the strength of functional relatedness of elements within a module” Each module should do one thing well. Aims for high cohesion. 不相干的不要放在一起 Reading: Basics of the Unix Philosophy

Cohesion Example public class MyClass { private int value1; public int Method1() return value1 + value2; } public int Method2() return value1 - value2; // doesn't belong on this class? public int Method3() return value3 * 2; Cohesion Example

Connected by Clean Interface Reduce the dependencies between modules. Dependency leads to coupling. Strives for low-coupling Depends on (needs, uses) A B 改了B可能就要改A

Degree of Coupling Uncoupled - no dependencies Loosely coupled - some dependencies High coupling makes modifying parts of the system difficult, Highly coupled - many dependencies

(Hidden) Data Coupling Undesirable data coupling may not be easy to notice. More discussion next time. public class HiddenCoupling { public bar someMethod(SomeType x) { AnotherType y = x.getY(); y.foo(); // blah; blah; ba; } B, X, internal representation of X, and Y are coupled

Modularity: Cohesion and Coupling Effective modularization = max. cohesion within modules + min. coupling between modules

Modules and Testing Testing a module Testability: 好不好測試,尤其是寫程式測程式 Isolation and Mockup Objects

Software Modularization As software is very flexible, software modularization may not be an easy task.

Customization or Made by Composition (more later) 沙堡 versus 樂高

如何切模組? Module granularity? 劃分的標準與原則? Modularization 如何切模組? Module granularity? 劃分的標準與原則?

Module Decomposition Top-Down Approach Bottom-Up Approach Hybrid: 下上下上 Action (Verb) Oriented Bottom-Up Approach Object (Noun) Oriented Hybrid: 下上下上

Top-Down Design: Decomposition into Modules Module A 分工合作 Module A1 Module C Module B Module A11 Module A12

Case Study The KWIC Example Key Word In Context (KWIC) About modularization

A Classical Paper on Modularity David Parnas “On the Criteria To Be Used in Decomposing Systems into Modules” Comm. ACM 15, 12 (Dec. 1972), 1053-1058 Discusses “modularization” Describes two ways to modularize a program that generates KWIC (Key Word in Context) indices.

Exercise

The KWIC Program

Key Word in Context Input: sort Output: The C Programming Language C Programming Language The Cat in the Hat The Hat The Cat in the Language The C Programming Programming Language The C The C Programming Language The Cat in the Hat in the Hat The Cat the Hat The Cat in Input: The C Programming Language The Cat in the Hat Cyclic shift The C Programming Language C Programming Language The Programming Language The C … The Cat in the Hat Cat in the Hat The sort

Design for the KWIC Problem What modules to have? Input-Process-Output

Solution 1 Input-Process-Output Function modules

Architecture of Solution 1 Function modules Direct Memory Access Shared data I/O Media Processing Subprogram Call System I/O Master Control 1 3 4 5 Input Circular Shift Alphabetizer Output 2 Viewed graphically, this architecture is centered on a set of shared data structures. A master controller determines the ordering of processing steps. Alphabetized Characters Index Index Output Input 潛在問題? Medium Medium file

背景補充說明 1972年代,大型主機電腦的記憶體以word為單位,長度可能是36~80(?) bytes 一個字元如果占8個bytes, 一個word可以儲存4個以上的字元 為提升效率,論文中的circular shift可能只是以改變每個字的index來實現,而非真的搬移字元。 論文中一些關於characters, word, index等的部份,現今應可以略過。

Shared Data Storage 2-D circular-shift array Abb.: TU Graz (siehe Literatur/ Links auf Folie 30)

Index Structures Abb.: TU Graz (siehe Literatur/ Links auf Folie 30)

Java Code for Modularization 1 Source code available for downloading public class Kwic { /* shared data structure*/ public static void main(String[] args) { // file name to read KWIC kwic = new KWIC(); if (args.length != 1) { System.err.println( "KWIC Usage: java kwic.ms.KWIC file_name"); System.exit(1); } kwic.input(args[0]); kwic.circularShift(); kwic.alphabetizing(); kwic.output(); private char[] chars_; private int[] line_index_; private int[][] circular_shifts_; private int[][] alphabetized_;

Problems of Solution 1: No Interfaces Direct Memory Access Shared data I/O Media Processing Subprogram Call System I/O Master Control Input Circular Shift Alphabetizer Output Alphabetized Characters Index Viewed graphically, this architecture is centered on a set of shared data structures. A master controller determines the ordering of processing steps. Index 共用資料 Data coupling Output Input Medium Medium 一旦資料格式改變,相關模組都要跟著改變。

延伸思考:Design for testability How do you do unit testing for Solution I? Difficult as it lacks clean interfaces for the modules No API

Background of Parnas’ Idea 提出另一種模組化的切割作法(ADT) Because maintenance costs dominate development costs, it is desirable to design a system that can easily adapt to change Change is costly when a whole system must be examined/altered to deal with a “small” change Anticipate changes Importance of Modularization

Parnas: What is a Module? A Work Assignment. Not a PL unit Represented by a design decision specific to itself and unknown to other modules Support flexibility in implementation Do Not represent steps in processing Low coupling, high cohesion.

Terminology Module - parts that can be put together to make a complete system - work assignment, subroutine, memory load , functional component Information Hiding - design principle Encapsulation - language facility for enforcing information hiding. (private/public in C#/Java)

Modularization 2 for KWIC Maintain same flow of control, but Organize solution around set of data managers (objects): for initial lines shifted lines alphabetized lines Each manager: handles the representation of the data provides procedural interface for accessing the data (API) Now consider an alternative architecture in which the data is no longer shared, but rather encapsulated in a set of objects that are accessed through their procedural interfaces.

KWIC: Solution 2 What important decisions to hide? Information hiding as a tool for modularization What important decisions to hide? hide data representation could be array + indices, as before or lines could be stored explicitly hide internal algorithm used to process that data could be batch or interactive processing …

Architecture of Solution 2 Subprogram Call Master Control Processing System I/O I/O Media 1 8 Input 4 6 Output 5. get 3. set 7. get 9. get 2 10 But now the shared data structures are absent, and each of the computational elements has a well-defined interface. The design is more “object oriented”. Alphabetic Shifts LineStorage Circular Shift Input Medium Output 3 Data Modules (managers) Medium

Solution 2: Modularization Module 1: Line storage Manages lines and characters; procedural interface Storage format: not specified at this point Module 2: Input Reads data lines and stores using “Line Storage” Module 3: Circular Shift Provides access functions to characters in circular shifts Requires SETUP as initialization after Input is done We have many of the same modules as before.

Solution 2: Modularization (Cont’d) Module 4: Alphabetize Provides index of circular shift (ITH) ALPH called to initialize after Circular Shift Module 5: Output Prints formatted output of shifted lines Module 6: Master Control (main) Handles sequencing of other modules

Slightly Revised Architecture of Solution 2 (Java Code available for downloading) (Kwic class) 3 Data Modules (managers)

KWIC 2: Input and Storage LineStorage lines = new LineStorage(); Input input = new Input(); // text file into LineStorage lines input.parse(file, lines); LineStorage: two-dimension ArrayList This is a book API lines

KWIC 2: Input and Storage (2/2) LineStorage lines = new LineStorage(); Input input = new Input(); // text file into LineStorage lines input.parse(file, lines); Input. parse(..) public void parse(String file, LineStorage line_storage){ try{ BufferedReader reader = new BufferedReader(new FileReader(file)); String line = reader.readLine(); while(line != null){ StringTokenizer tokenizer = new StringTokenizer(line); if(tokenizer.countTokens() > 0) line_storage.addEmptyLine(); while(tokenizer.hasMoreTokens()) line_storage.addWord(tokenizer.nextToken(), line_storage.getLineCount() - 1); line = reader.readLine(); } }catch(FileNotFoundException exc){

KWIC.execute() //main Create objects (modules) Start the work to do public void execute(String file) { LineStorage lines = new LineStorage(); Input input = new Input(); CircularShifter shifter = new CircularShifter(); Alphabetizer alphabetizer = new Alphabetizer(); Output output = new Output(); input.parse(file, lines); // text file into LineStorage lines shifter.setup(lines); alphabetizer.alpha(shifter); output.print(alphabetizer); }

Source code available public class Kwic { public static void main(String[] args){ if (args.length != 1){ System.err.println("KWIC Usage: java kwic.ms.KWIC file_name"); System.exit(1); } KWIC kwic = new KWIC(); kwic.execute(args[0]); // master control public void execute(String file) { LineStorage lines = new LineStorage(); Input input = new Input(); CircularShifter shifter = new CircularShifter(); Alphabetizer alphabetizer = new Alphabetizer(); Output output = new Output(); input.parse(file, lines); // text file into LineStorage lines shifter.setup(lines); alphabetizer.alpha(shifter); output.print(alphabetizer); Source code available

shifter.setup(lines) public void setup(LineStorage lines) { shifts_ = new LineStorage(); for (int i = 0; i < lines.getLineCount(); i++){ String[] line = lines.getLine(i); for (int j = 0; j < line.length; j++){ shifts_.addEmptyLine(); for (int k = j; k < (line.length + j); k++) shifts_.addWord( line[k % line.length], shifts_.getLineCount() - 1); }

Sequence Diagram for KWIC, 2 time

Effects on Current Programming “Fathered” key ideas of ADT (OOP): Information hiding Encapsulation before functional relations Easier understandability/maintainability Design more important than implementation Good design leads to good implementation Proper design allows for different implementations (easily modifiable)

Possible Changes: Change the Input Mode 將以檔案輸入方式 改成以 交談式方式輸入文字列 p之後輸出結果: Add, Print, Quit: a Star Wars The Empire Strikes Back The Return of the Jedi Add, Print, Quit: p Back The Empire Strikes Empire Strikes Back The Jedi The Return of the Return of the Jedi The Star Wars Strikes Back The Empire The Empire Strikes Back The Return of the Jedi Wars Star of the Jedi The Return the Jedi The Return of

Change of Input Style

延伸思考:Design for testability How do you do unit testing for Solution I? Difficult as it lacks clean interfaces for the modules No API

UI v.s. API UI: User <-> Program API: Program <-> Program

應用系統的基本架構: UI Traditional approach: Input – Process – Ouput (IPO) 對比:分為 (G)UI and Functional Part (FP) AP API UI FP

Advantages of Tiered Approach Easily replace UI Easily enhance FP Facilitate Regression Tests Regression Tester Prog. API UI FP 注意:單向或雙向 Model-View-Controller next time.