Program Design ( プログラム設計)

66
Program Design ( プププププププShaoying Liu ( プ ププFaculty of Computer and Infor mation Sciences Hosei University Email: [email protected] URL: http://cis.k.hosei.ac.jp /~sliu/

description

Program Design ( プログラム設計). Shaoying Liu ( 劉 少英) Faculty of Computer and Information Sciences Hosei University Email: [email protected] URL: http://cis.k.hosei.ac.jp/~sliu/. The goal of this course (この課程の目標). What is program design about (プログラム設計とは) Process of program design (プログラム設計プロセス) - PowerPoint PPT Presentation

Transcript of Program Design ( プログラム設計)

Page 1: Program Design  ( プログラム設計)

Program Design ( プログラム設計)

Shaoying Liu ( 劉 少英)Faculty of Computer and Information Scien

ces

Hosei University

Email: [email protected]

URL: http://cis.k.hosei.ac.jp/~sliu/

Page 2: Program Design  ( プログラム設計)

The goal of this course(この課程の目標)

What is program design about (プログラム設計とは)Process of program design (プログラム設計プロセス)Principles of program design (プログラム設計原理)Methods for program design (プログラム設計方法)Representations of program design (プルグラム設計の表現)Other related issues in program design (関連する問題)

Page 3: Program Design  ( プログラム設計)

The way to study this course(この課程の勉強仕方)

Attend lectures (授業に出席する) Take the class of Program Design Experiment(「プログラム設計演習」を取る)

Page 4: Program Design  ( プログラム設計)

The conditions for getting the credit of the course Program Design

( プログラム設計の単位をとる条件)

Attend the class (20%) (授業に出席すること。20% ) Pass the final examination (80%) (最終試験を合格すること。 80% )。

Page 5: Program Design  ( プログラム設計)

The conditions for getting the credit of the course Program Design Experiment

(プログラム設計演習の単位を取る条件

Attend the class (20%) (授業に出席すること。20% )Do exercises in the class (30%) ( 授業で練習問題をする。 30% )Complete a small project (50%) ( 一つの小さなプロジェクトを完成する。 50%)

Page 6: Program Design  ( プログラム設計)

Reference books(参考書)

“Software Design”, by David Budgen, Addison-Wesley, 1994. ISBN: 0-201-54403-2. “ プログラム設計” , 林雄二著、森北出版株式会社、1996年。 ISBN: 4-627-82250-2.“ ソフトウェア工学の基礎”、玉井哲雄著、岩波書店、

  2004。 ISBN:4-00-005608-5.“ 構造化分析とシステム仕様” , トム・デマルコ著、

 高梨智弘訳、日経BP出版センター、2000年。 ISBN: 4-8227-1004-1.

“Fundamentals of Object-Oriented Design in UML”, by Larry L. Constantine, Dorset House Publishing and Addison-Wesley, 2000.

ISBN: 0-201-69946.

Page 7: Program Design  ( プログラム設計)

The contents of this course(この授業の内容)

Part I: Overview of program design (プログラム設計について)Part II: Structured design methods and

representations (構造化設計と表示)Part III: Object-Oriented design methods and

UML (Unified Modeling Language) (オブジェクト指向設計と UML)Part IV: Documentation (設計文書)

URL: http://cis.k.hosei.ac.jp/~sliu/

Page 8: Program Design  ( プログラム設計)

Part I: Overview of program design

(プログラム設計について)

Page 9: Program Design  ( プログラム設計)

1. Introduction to program designプログラム設計の紹介)

What is design (設計とは) What is a program (プログラムとは) What is program design (プログラム設計とは) Principles of program design (プログラム設計の原理) Overview of design methods (設計方法の紹介)

Page 10: Program Design  ( プログラム設計)

1.1 What is design

When building any complex products, such as cars, bridges, houses, computers, airplanes, trains, and so on, it is always necessary to make a well-documented plan to tell how to build them, before they are actually built. The process and activity for making and documenting such a plan is called design.

(製品の設計とは、その製品を製造するために必要な計画又はモデルを作成するプロセスと活動である)

Page 11: Program Design  ( プログラム設計)

Example

1. Study user requirements: build a house with the following parts:

two sides

one end

one door

two roof panels

one front

Page 12: Program Design  ( プログラム設計)

2. Build an abstract model of the house (abstract description of the solution)

2 sides

1door

2 roofpanels

1 end

1 front

Page 13: Program Design  ( プログラム設計)

3. Evaluate the model against the user requirements.

4. Modify and refine the abstract model to produce

a detailed model of the house.

1 back

1 front

2 ends

2 roof panels

Living room

Kitchen

Bedroom1Bedroom2

Bedroom3

toliet bathroom

front door area

Page 14: Program Design  ( プログラム設計)

Product

User requirements

Design

Product

User requirements

Design

Abstract model

Page 15: Program Design  ( プログラム設計)

Description: design is a process of constructing a

preliminary plan or model for

producing an expected product or

object.

(設計とは、製品を生産するために必要な計画又はモデルを作成するプロセスと活動である。)

Page 16: Program Design  ( プログラム設計)

1.2 What is program

Description: a program is an algorithm written in a

programming language that provides

behaviors.

(プログラムとは、一定のプログラミング言語で書いたある機能を持つアルゴリズムである。) Program = Algorithm

+ Data structure

Page 17: Program Design  ( プログラム設計)

Description: an algorithm is a sequence of actions or commands.(アルゴリズムとは、操作又は命令の並びである。)

Example: compute the average score of a class with 40 students. (40人を持つクラスの平均

成績を求める。) (1) Input all scores of the class (クラス全員の成績の入

力) (2) Compute the total score of the class (成績の合計の計

算) (3) Divide the total score of the class by the number of students in the class  (合計を学生の人数で割る) (4) Print out the average score (平均成績のプリント)

Page 18: Program Design  ( プログラム設計)

A Java-like program for the average score problem:

int number = 0, totalScore = 0;

double averageScore = 0;

//these variables represent date structures

for (int count = 0; count <= 39; count++)

{

number = read a score;

totalScore = totalScore + number;

}

avergeScore = totalScore / 40;

System.out.println(“The average score is:” + averageScore);

Page 19: Program Design  ( プログラム設計)

Mathematical abstraction of a program: a program is a function: (プログラムの意味は数学の関数で表す。)

P: D --> R

where P denotes a program; D is its domain; and R is its range. ( P はプログラム、 D はドメイン、      R は値域である)

In fact, the essential task of constructing a program is todetermine the following two elements: (プログラムの作成は、次のような二つのことが決まることである) (1) domain and range (ドメインの決まり) (2) definition of the function P (関数 P の定義又は表現)

Page 20: Program Design  ( プログラム設計)

1.3 What is program design

Description: program design is a process of

constructing a preliminary plan or

model for producing an expected

program.

(プログラム設計とは、期待されたプログラムを作成するために必要な計画又はモデルを作成するプロセスである)

Page 21: Program Design  ( プログラム設計)

When is program design carried out in the software development process?(設計はいつ行われるのか。)

Requirements specification

Program design

Coding

Abstract design

Detailed design

Page 22: Program Design  ( プログラム設計)

Abstract design: it covers the following activities: Identify necessary components, including data items and operations. This may include definitions of the data items and the functionalities of the operations.(データと操作の発見及び定義) Determine the architecture (or structure) of the program that indicates the way to integrate the operations at an abstract level. (プログラムの構造の描画) Determine relations between data items and operations. For example, what operation processes what data items. (データと操作の間の関係の定義)

Page 23: Program Design  ( プログラム設計)

Detailed design: it covers the following activities: Define concrete data structures for all the data items identified in the abstract design. Usually, these data items are defined using the data structures available in a specific programming language (e.g., Java, C). (データ項目のデータ構造が決まる) Define the functionality of the operations identified in the abstract design in detail. (操作の機能を定義する) Determine algorithms for implementing the operations. (操作の機能を実装するアルゴリズムが決まる) Establish precise logical relations between operations. For example, under what conditions which operations can be integrated to provide what behavior. (関連する操作の論理的な関係が決まる)。

Page 24: Program Design  ( プログラム設計)

Characteristics of program design(プログラム設計の特徴)

The process of program design lacks a definitive formula to follow. In other words, there is no absolute rule for design. This is different from solving a mathematical problem. (プログラム設計には、確定的な数式がない)There is a lack of quality measures that can be used to establish that any program design is the ‘best’ one possible. (プログラムが最高かどうかを評価する基準がない)There is no true or false program design, but good or bad. (真の設計か偽の設計かを決められない。良い設計か良くない設計かを決められる)Program design is a process of creating problems and resolving problems. (プログラム設計は、問題を作りながらそれらの問題を解決するプロセスである)Program design is an intellectually rigorous discipline. (プログラム設計は、知的、厳密的な作業である)

Page 25: Program Design  ( プログラム設計)

Questions to think about

What is the goal of program design?

What is a program?

Can you give an example that describes the process of designing and implementing a product?

What is the relationship between a design and a program? Should the design documentation be

part of the program?

Page 26: Program Design  ( プログラム設計)

1.4 Program qualities achievable by design

(設計で獲得できるプログラムの品質)

Reliability – a measure of continuous delivery of proper service. It reflects the degree to which a program satisfies its requirements that specifies the proper services. For example, a car, TV set, computer. (信頼性ー適当なサービス を連続的に提供する程度)

Page 27: Program Design  ( プログラム設計)

Correctness – a property that a program satisfies its functional specification for any input in its domain. (正確性ープログラムが機能仕様を満たすかどうかの性質)

Since there is usually a gap between real requirements and the specification that is supposed to document the requirements, a program is correct does not necessarily mean it is 100% reliable.Efficiency – a measure of the running speed of a

program and the consumption of memory during operations. (効率ープログラムの実行速度と使ったメモリ

量のこと)Usability – a measure of how easily a program can be used in its operation. (有用性ープログラムがどのような簡単に使われること)Maintainability – a measure of how easily a program can be modified or extended after it is delivered for operation. (保守性ープログラムをどのように簡単に修正又は拡大すること)

Page 28: Program Design  ( プログラム設計)

Readability – a measure of how easily a program can be read and understood. (読みやすさ又は可読性ープログラムはどのような簡単に読み、理解できること)Reusability – a measure of how easily a program or its components can be reused for building different parts of the same program or other programs. (再利用性ープログラム又はプログラム部品はどのような簡単に他のプログラム又は部品に利用されること)

• Robustness – a measure of a program’s ability to recover gracefully whenever a failure occurs. (Typical failures are memory violations, external device errors, and arithmetic overflows). For example, exception handling in Java is a mechanism to enhance the robustness of programs. (健壮性ープログラムは失敗から順調 に回復する能力)

Page 29: Program Design  ( プログラム設計)

Classification of the qualities(プログラム品質の分類)

Reliability, correctness, efficiency, and usability are the qualities that are great concern of the users. (ユーザの関心が高い性質)Maintainability, readability, reusability, and robustness are the qualities that are great concern of the program developers. (プログラムの開発者の関心が高い性質)

Page 30: Program Design  ( プログラム設計)

How to achieve program qualities by program design

(プログラムの品質は設計でどのように得られるのか)

Design programs with good principles. (良い原理でプログラムを設計すること)Design programs with effective methods. For example, top-down, bottom-up, modular, structured, and object-oriented designs (which will be explained later). (有効な設計方法を使うこと)Design programs with comprehensible notations. For example, graphical notations, structured English. (理解しやしい言語又は表記法でプログラムの設計を表すこと)

Page 31: Program Design  ( プログラム設計)

1.5 Principles of program design(プログラム設計の原理)

Abstraction and decomposition. (抽象と分解)Abstraction is a way to express the most important information of the program without telling its implementation details. (抽象は具体的な情報を含まない最も重要な情報を表す手法である)Decomposition is a way to divide a big task into small tasks, and to develop details of an abstraction. The benefit of decomposition is to reduce the complexity of programs. (分解は大きなタスクを小さなタスクに割り、抽象したものを詳細する手法である)

Page 32: Program Design  ( プログラム設計)

For example, description of Hosei University:

(例えば、法政大学の描画)

Abstraction: Hosei University has three campus: Ichigaya, Koganei, and Tama campuses.

(抽象:法政大学は、市ヶ谷、小金井、及び多摩という三つのキャンパスを持つ大学である。)

Page 33: Program Design  ( プログラム設計)

Decomposition: Ichigaya campus has faculties of Business Administration, Law, Letters, Intercultural Communication, Humanity   and Environment. Koganei campus has faculties of Engineering, and Computer and Information Sciences. Tama campus has faculties of Economics, Social Sciences, and Social Policy and Management.

(分解:市ヶ谷キャンパスでは、経営学部、法学部、文学部、国際文化学部、人間環境学部がある。小金井キャンパスでは、工学部と情報科学部がある。多摩キャンパスでは、経済学部、社会学部、及び現代福祉学部)

Page 34: Program Design  ( プログラム設計)

Encapsulation (カプセル化 ) Encapsulation is the grouping of related ideas into one

unit, which can thereafter be referred to by a single name.(カプセル化は、関連するプログラム部品(データ、操作)を一つのプログラム単位に入れる)

For example,

class Stack

int[] a = new int[10];

int top = 0;

Initialize;

Push;

Pop

Page 35: Program Design  ( プログラム設計)

top

Empty stack

topxyz

Stack after pushingx, y, and z

topxy

Stack after popping up z

a a a

Page 36: Program Design  ( プログラム設計)

Information hiding (情報隠蔽) Information hiding is the use of encapsulation to restrict from

external visibility certain information or implementation decisions that are internal to the encapsulation structure. (情報隠蔽とは、カプセル化という仕組みにより必要なデータ情報又は操作の実装情報を制限する)

For example, class Stack private int a[] = new a[10]; private int top = 0; public Initialize; public Push; public Pop;  public Other necessary operations;

Page 37: Program Design  ( プログラム設計)

Modularity (モジュール化) Modularity is a property that a program consists

of many independent modules. A module is a modest-sized component that performs independently specific functions. (モジュール化は、プログラムを規模が小さい多数のモジュールから構成させる)

For example, computers, cars, Japanese food.

To support these principles, many design methods have been developed, which are introduced next.

Page 38: Program Design  ( プログラム設計)

Questions to think about

Let us take car as a product. Explain the following qualities of the car, with examples.

• Reliability• Correctness• Efficiency• Usability• Maintainability• Extendability• Reusability• Robustness

Page 39: Program Design  ( プログラム設計)

1.6 Overview of Design methods(設計方法の紹介)

Top-down design (トップ ーダウン設計) Bottom-up design (ボトム ーアプ設計) Modular design (モジュール式の設計) Structured design (構造化設計) Object-Oriented design (オブジェクト指向設計) Component-based design (分品に基づく設計)

Page 40: Program Design  ( プログラム設計)

1.6.1 Top-down design(トップ ーダウン設計)

Top-down design supports the “abstract and decomposition” principle. By this design method, a system is first abstracted as a high level unit (e.g., module, process, procedure, function), and then decomposed into low level units, possibly integrated together using some constructs. Usually such a decomposition process focuses on either data flow or control flow of the program.

(トップ ーダウン設計は、抽象と分解という設計原理を支

える)

Page 41: Program Design  ( プログラム設計)

For example, a “University Information System” is designed using top-down method as follows:

(大学情報システムをトップ ーダウンで設計する)

Top level:

UniversityInformation System

Page 42: Program Design  ( プログラム設計)

Decomposition:

UniversityInformation System

Course managementResearch

management

Page 43: Program Design  ( プログラム設計)

Decomposition:

UniversityInformation System

Course managementResearch

management

Lecture managementExaminationmanagement

Study recordsmanagement

Page 44: Program Design  ( プログラム設計)

Decomposition:

UniversityInformation System

Course managementResearch

management

Lecture managementExaminationmanagement

Study recordsmanagement

Projectsmanagement

Publicationsmanagement

Reserach- relatedevents management(e.g., conferences)

Page 45: Program Design  ( プログラム設計)

1.6.2. Bottom-up design(ボトム ーアプ設計)

Bottom-up design takes the opposite approach to top-down design:(1) First investigate the most important and crucial but low

level functions or modules of a program system. (まず低いレベルの重要なモジュールを設計する)

(2) Then integrate those low level modules into high level modules that is closer in meeting the requirements. (低いレベルのモジュールを統合して高いレベルのモジュールを構成する)

(3) Integrated modules are also treated as well-designed low level modules in the integration process. (構成されたモジュールも他のモジュールを構成するために使われられるモジュールとなる)

Page 46: Program Design  ( プログラム設計)

For example, we start the design with investigating the following low level functions.

Lecture management

Examinationmanagement

Study recordsmanagement

Page 47: Program Design  ( プログラム設計)

Then the following functions:

Projectsmanagement

Publicationsmanagement

Reserach- relatedevents management(e.g., conferences)

Page 48: Program Design  ( プログラム設計)

Then we integrate those low level functions to construct more powerful functions:

Course managementResearch

management

Lecture managementExaminationmanagement

Study recordsmanagement

Projectsmanagement

Publicationsmanagement

Reserach- relatedevents management(e.g., conferences)

Page 49: Program Design  ( プログラム設計)

Finally, we build the entire design to meet the requirement:

UniversityInformation System

Course managementResearch

management

Lecture managementExaminationmanagement

Study recordsmanagement

Projectsmanagement

Publicationsmanagement

Reserach- relatedevents management(e.g., conferences)

Page 50: Program Design  ( プログラム設計)

The comparison between top-down and bottom-up design methods: (トップ ーダウン設計とボトム ーアプ設計の比較)Top-down design is a process of development from abstract ideas to concrete ideas. (トップ-ダウン設計は、抽象表現から詳細表現へ発展するプロセスである)Bottom-up design is a process of development from concrete ideas to abstract ideas, representing a synthesis (綜合) . (ボトム ーアプ設計は、具体的な表現から抽象表現へ発展するプロセスである)

Page 51: Program Design  ( プログラム設計)

Top-down is more suitable for designing program systems that is not familiar to the designer, whereas bottom-up approach is more suitable for designing familiar program systems. Using what design method should depend on how much you are familiar with the domain. (トップ-ダウン設計は、新しいシステムの開発に有効である。ボトム ーアプ設計は、既に良くしているドメイン の新しいシステムの開発に有効である。

Top-down design supports “goal-oriented” approach in a natural manner, therefore, has less risk in designing an unsatisfactory program, whereas bottom-up design is opposite to the goal-oriented approach, therefore, has more risk in designing an unsatisfactory program. (トップ-ダウン設計では、ゴール指向設計を支えるから、満足でないシステムを作成するリスクが少ない。ボトム ーアプ設計では、そのリスクが相対的に大きい。

Page 52: Program Design  ( プログラム設計)

1.6.3 Modular design(モジュール式の設計)

Modular design is way of designing a program as a set of related modules. (モジュール式の設計は、いくつかのモジュールを設計することによりプログラム全体を設計する手法である)

A module is a modest-sized subprogram that performs independently one specific function. (モジュールは、

一つの機能を実装する普通の規模のプログラム単位)

The emphasis of modular design is on the concept: a set of modules, not on the way to achieve it. One can build such a set of modules either using top-down or bottom-up method.

Page 53: Program Design  ( プログラム設計)

The characteristics of a module: (モジュールの特徴)

modest-size. (普通の規模)Independent performance of a specific function. (一つの独立な機能を持つ)Encapsulation of data and operations. (データと操作のカプセルにする)Implementation hiding. (実装の詳細情報を隠蔽する)Replaceable. That is, if we substitute a new module of different design for an old one and maintain the same function (or behavior), the entire program system should work well with little or no change. (置き換えられる)

For example, a car is composed of many components, including engine, car body, wheels, battery, and so on.

Page 54: Program Design  ( プログラム設計)

1.6.4 Structured design(構造化設計)

Structured design is a way to achieve programs that are composed of only single-entry and single-exit control constructs in a hierarchical fashion. A program satisfying such a property is called structured program. (構造化設計とは、階層的な構造で、「一つの入口と一つの出口」を持つプログラムを設計する手法である)

A structured program offers the following advantages:

Easy to read and understand. (プログラムは読みやすい)Easy to test and debug. (テスト及びデイバグしやすい)Easy to prove the correctness. (プログラムの正確性の証明が容易である)

Page 55: Program Design  ( プログラム設計)

In general, there are three kinds of single entry and single exit constructs: sequence, choice (or selection), and iteration. These three constructs are usually expressed using the following three statements in a programming language: (「一つの入口と一つの出口」を持つプログラム構造が次の三つである)

S1; S2 if C then S1 else S2 (or if (C) S1 else S2) while C do S (or while (C) S)

The flowcharts of these constructs are:

Page 56: Program Design  ( プログラム設計)

C

task1 task2

yes notask1

task2

C

task1

yes no

Sequence Choice Iteration

Page 57: Program Design  ( プログラム設計)

The hierarchical structure of a program is created when calling subprograms (or modules, procedures (Pascal), functions (C), methods (Java)). (プログラムの階層的な構造は、モジュールの呼び出しにより、 「一つの入口と一つの出口」の性質を維持しながら形成された)

The characteristics of such a hierarchical structure is to keep the property of single-entry and single-exit.

Page 58: Program Design  ( プログラム設計)

Subprogram1calling point;return point;

Subprogram2calling point;return point;

Subprogram3calling point;return point;

Subprogram10calling point;return point;

Page 59: Program Design  ( プログラム設計)

Although structured design is not necessarily carried out in top-down and modular manner, experience in practice shows that top-down and modular manner is the most effective way to achieve good quality structured programs.

Therefore, structured design is usually interpreted as the combination of top-down and modular design that achieves single-entry and single-exit programs.

Page 60: Program Design  ( プログラム設計)

Structured design = Top-down

+

Modular

+

Hierarchical

design

(構造化設計=トップ-ダウン +         モジュール式 +          階層的な設計)

Page 61: Program Design  ( プログラム設計)

1.6.5 Object-oriented design(オブジェクト指向設計)

Object-oriented design is a way of designing a program system by focusing on the design of objects and their integration. (オブジェクト指向設計とは、オブジェクト及びオブジェクトの間の関係を重視しながらプログラムを設計する手法である)

An object is an encapsulation of attributes and operations (or methods); it takes inputs and performs some functions. In fact, an object is a kind of module. (オブジェクトは、属性(データ)と操作をかぶせる化したものである)

An object-oriented program can be regarded as a network of objects that interact with each other by means of sending and receiving messages (which are similar to calling methods in Java).

Page 62: Program Design  ( プログラム設計)

Obj6

Obj1

Obj2

Obj3

Obj4

Obj5

Obj0

Page 63: Program Design  ( プログラム設計)

1.6.6 Component-based design(部品に基づく設計)

Component-based design is an approach to designing a program using well-constructed software components that are available for use. (部品に基づく設計は、既に構築されてあるプログラム部品(モジュール)を用いてプログラムを作成する手法である)

Abstractly, a component is like a module, which performs a

specific function under a certain condition. It is a basic block for building programs. Of course, a component can be either simple or complex, either small or large.

Specifically, a component can be a function, object, or their integration. There is no agreed, unique, and formal definition of component.

Page 64: Program Design  ( プログラム設計)

In fact, component-based design is a specialization of modular design method, with the following characteristics: (部品に基づく設計は、モジュール式の設計の一つである)(プログラム部品が次の特徴を持つはずである)Components are well-constructed and ready to use. (部品は、既に使われられる状態である)Components’ interfaces and functions are well-defined.(部品のインタフェースと機能が良く定義されている)Components can be plug in to program systems easily.(部品は、プログラムに簡単に投入できる)Components are usually language-specific. (部品は、一般てきに言語特定である)

(for example, Java AWT and SWING offer powerful components for building Java programs).

Page 65: Program Design  ( プログラム設計)

Exercise 1

(1) Give an example to explain the following concepts (事例を用いて、次の概念を説明しなさい)ReliabilityCorrectnessEfficiencyUsabilityMaintainabilityReusabilityRobustness

Page 66: Program Design  ( プログラム設計)

(2) Give an example to explain the following design methods (事例を用いて次の設計方法を説明しなさい)

Top-down design

Bottom-up design

Modular design

Component-based design

Object-Orient design