8. Transformation from design
representations into programs
(設計からプログラムへの変換)
In this part you will learn:(主な内容)
Transformation of DFDs(DFDの変換)
Transformation of hierarchical DFDs(階層的な
DFDの変換)
Transformation of data definitions(データ定義の
変換)
8.1 Transformation of DFDs
(DFDの変換)
Problem:
Design
(DFD)
Data flow
Structured
Transform
Program
(Java)
Control flow
Object-Oriented
Let us consider the following DFD:(次のDFDを考えましょう)
a2
a1
a3
B
A
a4
C
s
General strategy for transformation:(変換の方法)
Define a class for each DFD.(一つのDFDに対して、一つ
のクラスを定義する)
All of the data stores occurring in the DFD are declared as
instance variables of the class.(データ倉庫はクラスのイ
ンスタンス変数で実装する)
Each process of the DFD is defined as a method of the
class.(DFDのプロセスは、クラスのメソッドで実装する)
• The data flow connections between processes can
be implemented as method invocations (or method
calls) in the class.(データフローは、メソッドの呼
び出しで実装する)
8.1.1 Transformation of a simple DFD
with no stores
(データ倉庫を持たないDFDの変換)
a2
a3
B
a1
A
C
a4
Let G denote this DFD.
The feature of this DFD is that each process has
only one output data flow.(このDFDの特徴は、プロ
セスが一つの出力データフローしか持たない)
8.1.1.1 Specific strategy 1(具体的な変換方法)
class G {
a2_type A(a1_type a1){
Produce a2 based on a1;
return a2;
}
a4_type F(a1_type a1){
a2_type a2;
a3_type a3;
a4_type a4;
a3_type B(a2_type a2){
Produce a3 based on a2;
return a3;
}
a2 = A(a1);
a3 = B(a2);
a4 = C(a3);
return a4;
a4_type C(a3_type a3){
Produce a4 based on a3;
return a4;
}
}
}
8.1.1.2 Specific strategy 2(具体的な変換方法)
class G {
a2_type A(a1_type a1){
Produce a2 based on a1;
return a2;
}
a4_type B(a1_type a1){
a2_type a2;
a3_type a3;
a4_type a4;
a4_type C(a3_type a3){
Produce a4 based on a3;
return a4;
}
a2 = A(a1);
Produce a3 based on a2;
a4 = C(a3);
return a4;
}
}
8.1.1.3 Specific strategy 3(具体的な変換方法)
class G {
a3_type B(a2_type a2){
Produce a3 based on a2;
return a3;
}
a4_type A(a1_type a1){
a2_type a2;
a3_type a3;
a4_type a4;
a4_type C(a3_type a3){
Produce a4 based on a3;
return a4;
}
Produce a2 based on a1;
a3 = B(a2);
a4 = C(a3);
return a4;
}
}
8.1.2 Transformation of a complex
DFD with no stores(データ倉庫を持
たない複雑なDFDの変換)
Let G1 denote the following DFD:
a2
a1
a5
B
A
D
a4
a3
C
a7
a6
The feature of this DFD is that some processes
have more than one output data flows.(このDFDの特徴は、
あるプロセスが二つ以上の出力データフローを持つ)
DFD G1 is transformed into the following class:
class G1 {
a1_type a1;
a2_type a2;
a3_type a3;
a4_type a4;
a5_type a5;
a6_type a6;
a7_type a7;
void A() {
Produce a2 and a3
based on a1;
}
void B() {
Produce a4 and a5
based on a2;
}
void C() {
Produce a6
based on a3 and a4;
}
void D() {
Produce a7
based on a5 and a6;
}
a7_type F() {
A(); //produce a2
B(); //produce a4 and a5
C(); //produce a6
D(); //produce a7
return a7;
}
Note that the order of B()
and C() in the body of method
F cannot be reversed. That is,
C(); B() is not correct.
8.1.3 Transformation of DFDs with
stores(データ倉庫を持つDFDの変
換)
Let G2 denote the following DFD:
a1
A
s1
B
Process A updates store s1 while process B reads
data from store s1.
a2
DFD G2 is transformed into the following class:(DFD G2
は、次のクラスへ変換した)
class G2 {
s1_type s1;
void A(a1_type a1) {
Update s1 based on a1;
}
a2_type B() {
a2_type a2;
Produce a2 based on s1;
return a2;
}
}
8.2 Transformation of hierarchical
DFDs(階層的なDFDの変換)
a1
a2
A
B
a3
High level DFD D1
a2
a1
A1
b1
b2
A3
A2
The decomposition D2 of process A
The general transformation strategy:(一般な変換し方)
Transform each DFD by following the guidelines
illustrated previously.(以前に議論した変換方法により
DFDを変換する)
If a process is decomposed into a DFD, the method
implementing the process can be defined by calling the
methods implementing the processes in its
decomposition.(DFDに分解されたプロセスをメソッドの
呼び出しに実装する)
The program outline transformed from the
hierarchical DFD given on the previous page is
given on the next page.
class D1 {
a2_type A(a1_type a1) {
a2_type a2; //local variable
Produce a2 based on a1;
return a2;
}
a3_type B(a1_type a1) {
a3_type a3;
a2_type a2; //local variable
a2 = A(a1);
Produce a3 based on a2;
return a3;
}
}
class D1 {
a2_type A(a1_type a1) {
a2_type a2; //local variable
b1_type b1;
b2_type b2;
b1 = A1(a1);
b2 = A2(b1);
a2 = A3(b2);
return a2;
}
a3_type B(a1_type a1) {
a3_type a3;
a2_type a2; //local variable
a2 = A(a1);
Produce a3 based on a2;
return a3;
}
}
//Produce a2 based on a1
8.3 Transformation of Data
definitions(データ定義の変換)
The transformation includes two aspects:
Transformation of elementary data items.(基本
データ項目の変換)
Transformation of composite data items.(複合
データ項目の変換)
8.3.1 Transformation of
elementary data items(基本デー
タ項目の変換)
nat0
nat
int
real
string
Enumeration
n..m
int
int
int
double
String
Vector or array of String
int
Notice that the above transformation is only a guideline.
8.3.2 Transformation of composite data
items(複合データ項目の変換)
1. Transformation of compositions:(合成の変換)
Guideline:
A composition can be transformed into a class
where each
component of the class is declared as an instance
variable.
(合成はクラスへ変換し、合成の部品データ項目
がそのクラスのインスタンス変数へ変換する)
For example, Let student be a composite data item
defined as follows:(例えば、studentは次のように
定義されている)
student = name + id + age + height + weight +
education
This composition is transformed into the class:(この
合成データ項目は、下記のようなクラスへ変換さ
れる)
class Studentty {
String
name;
int
id;
int
age;
double
height;
double
weight;
Educationty education;
}
Then student must be declared as an instance variable of
Studentty wherever appropriate:(そして、studentはインスタ
ンス変数として次のように宣言される必要がある)
Studentty student;
This declaration can be an instance variable of a class, a
formal parameter or a local variable of a method.(この宣
言は、クラスのインスタンス変数としても出来るし、メソッ
ドの仮引数又はローカル変数としても出来る)
2. Transformation of options(選びデータ項目の変換)
Guideline:
An optional data item in a composition should be treated
the same as normal data item.(合成の部品データ項目は、
普通(つまり、選ばない)のデータ項目として実装する)
For example, consider the composition:(次の事例を考え
よう)
a = x + (y) + z
Where y is an optional data item.
It is transformed into the class: (次のクラスへ変換される)
class Aty {
type1 x;
type2 y;
type3 z;
}
Then data item a should be declared as:(そして、データ項
目aは、次の通りに宣言する必要がある)
Aty a;
3. Transformation of choices(選択データ項目の変換)
Guideline:
A choice of data item can be transformed into a
class where each data item involved in the choice is declared
as an instance variable of the class.(選択データ項目は、ク
ラスへ変換される。ただし、選択されるデータ項目が、その
クラスの普通のインスタンス変数へ変換される)
For example, consider:(次の選択データ項目を考えよう)
gender = [male | female]
Data item gender is transformed into the class:(データ項目
genderを次のクラスへ変換される)
class Genderty {
boolean male;
boolean female;
}
Then data item gender is declared as:(そして、genderは次の
通りに宣言される)
Genderty gender;
Another way of transformation for this particular choice is:
(データ項目genderのもう一つの変換しかたは、次の通り
である)
boolean gender;
4. Transformation of iterations(反復データ項目
の変換)
Guideline:
An iteration of data items can be transformed into
a subclass of
Vector.(反復データ項目はVectorクラスのサブク
ラスへ変換されることができる)
For example, let’s consider the definition:(次の事例を考え
よう)
education = {course}
This definition can be transformed into the following class:
(データ項目educationは、次のクラスへ変換できる)
class Educationty extends Vector {
public Educationty() {
super();
}
}
Then data item education can be declared as:(そして、
educationは、次の通りに宣言する必要がある)
Educationty education;
Thus, education will be able to hold as many objects
(e.g., courses) as possible.
Notice
(注意事項)
1. There are no general rules for transformations from
DFDs into program structures, because the semantics of
DFDs is not precise. (DFDの操作意味が明確に定義し
ていないため、DFDをプログラムへの変換の一般の
ルールがまだ確立していない)
2. There are many ways to transform data definitions.(デー
タ項目の定義の変換しかたは、唯一でない)
3. The discussions about transformations from DFDs and
data definitions into programs only present guidelines,
not precise formulas.(上記のDFDとデータ項目の変換
は、一般のルールでなく、ガイドラインだけである)
Exercise 6(練習6)
1. Transform the following DFD into a program
structure.(次のDFDをプログラム擬似コードへ
変換しなさい)
c1
c2
c3
B
A
2. Transform the following DFD into a program
structure.(変換しなさい)
b
c4
c1
A3
A1
c3
c2
A2
3. Transform the following hierarchical DFDs into a
program structure.(次の階層的なDFDをプログラムの
擬似コードへ変換しなさい)
a1
a2
1
a3
2
Q
P
high level DFD
a1
b1
1.3
P3
1.1
P1
1.2
b2
P2
b3
The decomposition of process P
a2
4. Transform the composite data item teacher into a
type and variable declaration in a program language
(e.g., Java).(次のデータ項目teacherの定義をJava
の型と変数へ変換しなさい)
teacher = id + name + {course} + {class}
course = title + credit
class = classname + numberOfStudent
where all of the undefined data items involved in the
definition of teacher are regarded as elementary
data items. (ここで明確定義していない全ての
データ項目は、基本データ項目として考えられる)
Small project 1.4
(小プロジェクト)
Transform the DFD of the “Personal
Information Management System” designed
in small project 1.1 into a Java program pseudocode.
(Personal Information Management SystemのDFDをJavaプロ
グラム擬似コードへ変換しなさい)
Submission date: January 15, 2007.
(提出日:2007年1月15日)
Submission place: TA又は情報科学部事務室
(提出先: TA又は情報科学部事務室)
Submission contents: Design documentation and
Java pseudocode that are produced in small
project 1.1, 1.2, 1.3, and 1.4.
(提出内容:小プロジェクト1.1, 1.2, 1.3,及び1.4で作
成された設計書とJavaプログラム擬似コード)
ダウンロード

Program Design (プログラム設計)