2 Account customer new Account customer set Namename

  • Slides: 31
Download presentation

以下の 2つのコードは兄弟クラ ス間のクローンである 銀行口座の オブジェク ト生成 顧客名のセ ット : : Account customer = new

以下の 2つのコードは兄弟クラ ス間のクローンである 銀行口座の オブジェク ト生成 顧客名のセ ット : : Account customer = new Account(); customer. set. Name(name); customer. set. Number(number); customer. set. Rate(ORDINARY_RATE); Account customer = new Account(); customer. set. Name(name); customer. set. Number(number); customer. set. Rate(FIXED_RATE); : : 顧客番号の セット 差異 15 顧客名のセ ット 顧客番号の セット

手順1 -1:  メソッドの宣言,コンパイル : Account customer = new Account(); customer. set. Name(name); customer. set.

手順1 -1:  メソッドの宣言,コンパイル : Account customer = new Account(); customer. set. Name(name); customer. set. Number(number); customer. set. Rate(ORDINARY_RATE); : 18 : 親クラス に処理を 記述する Account customer = new Account(); customer. set. Name(name); customer. set. Number(number); customer. set. Rate(FIXED_RATE); :

手順1 -1:  メソッドの宣言,コンパイル void intial. Account(){ メソッドで返 す型はvoidに する : } Account customer =

手順1 -1:  メソッドの宣言,コンパイル void intial. Account(){ メソッドで返 す型はvoidに する : } Account customer = new Account(); customer. set. Name(name); customer. set. Number(number); customer. set. Rate(ORDINARY_RATE); : 19 : メソッドの名 前はメソッド の役割,処理 の内容から決 める Account customer = new Account(); customer. set. Name(name); customer. set. Number(number); customer. set. Rate(FIXED_RATE); :

手順1 -2:  クローン部の引き上げ void intial. Account(){ } : Account customer = new Account(); サブクラスから

手順1 -2:  クローン部の引き上げ void intial. Account(){ } : Account customer = new Account(); サブクラスから customer. set. Name(name); のコピーペース customer. set. Number(number); customer. set. Rate(ORDINARY_RATE); ト : 21 void intial. Account(){ Account customer = new Account(); customer. set. Name(name); customer. set. Number(number); customer. set. Rate(ORDINARY_RATE); } : Account customer = new Account(); customer. set. Name(name); customer. set. Number(number); customer. set. Rate(FIXED_RATE); :

手順1 -3: クローン部の差異以外の変数,オブ ジェクトの引数を用意する void intial. Account(){ Account customer = new Account(); customer. set.

手順1 -3: クローン部の差異以外の変数,オブ ジェクトの引数を用意する void intial. Account(){ Account customer = new Account(); customer. set. Name(name); customer. set. Number(number); customer. set. Rate(ORDINARY_RATE); } : : Account customer = 変数の名前 new Account(); customer. set. Name(name); をそのまま, customer. set. Number(number); 引数に宣言 customer. set. Rate(ORDINARY_RATE); : 23 void intial. Account( int number, String name){ Account customer = new Account(); customer. set. Name(name); customer. set. Number(number); customer. set. Rate(ORDINARY_RATE); } する Account customer = new Account(); customer. set. Name(name); customer. set. Number(number); customer. set. Rate(FIXED_RATE); :

手順1 -4: 戻り値があるならreturn文を追加し, メソッドの型を戻り値の型にする void intial. Account(int number, String name){ Account customer = new

手順1 -4: 戻り値があるならreturn文を追加し, メソッドの型を戻り値の型にする void intial. Account(int number, String name){ Account customer = new Account(); customer. set. Name(name); customer. set. Number(number); customer. set. Rate(ORDINARY_RATE); } : Account customer = new Account(); customer. set. Name(name); customer. set. Number(number); customer. set. Rate(ORDINARY_RATE); : 25 Account intial. Account(int number, String name){ Account customer = new Account(); customer. set. Name(name); customer. set. Number(number); customer. set. Rate(ORDINARY_RATE); return customer; : } Account customer = new Account(); customer. set. Name(name); customer. set. Number(number); customer. set. Rate(FIXED_RATE); : 戻り値がないときに はこの手順での操作 はない

手順1 -5: 差異のための引数を作成し, 差異を引数で置き換える Account intial. Account(int number, String name){ Account customer = new

手順1 -5: 差異のための引数を作成し, 差異を引数で置き換える Account intial. Account(int number, String name){ Account customer = new Account(); customer. set. Name(name); customer. set. Number(number); customer. set. Rate(ORDINARY_RATE); return customer; : } Account customer = new Account(); customer. set. Name(name); customer. set. Number(number); customer. set. Rate(ORDINARY_RATE); : 27 Account intial. Account(int number, String name, int rate){ Account customer = new Account(); customer. set. Name(name); customer. set. Number(number); customer. set. Rate(rate); return customer; : } Account customer = new Account(); customer. set. Name(name); 共通部分を customer. set. Number(number); customer. set. Rate(FIXED_RATE); 名前にして : いる

手順2: 元の子クラスのクローン部を取り除 き,メソッド呼び出しを追加する : Account customer = initial. Account(number, name, ORDINARY_RATE); : : Account

手順2: 元の子クラスのクローン部を取り除 き,メソッド呼び出しを追加する : Account customer = initial. Account(number, name, ORDINARY_RATE); : : Account customer = initial. Account(number, name, FIXED_RATE); : 各クラスをコンパイルして,テストする 30