=
ホーム
On Your Mark
ホーム
/
設計(Java)
/
【設計】 デザインパターン:Command
2013年10月5日土曜日
デザインパターン
設計(Java)
t
f
B!
P
L
# Command ## 概要 Commandは「指揮」や「命令」という意味です。<br /> 命令の情報をオブジェクトに設定し、引数で渡し命令を出すパターンです。<br /> ## ポイント 例えば、パスタを茹でる処理を実装しようとしたら、<br /> 鍋に水を入れて沸かす、パスタを茹でる、湯を切ってパスタを取り出す<br /> という流れになりますが、これらをそれぞれオブジェクトにし、<br /> 順に処理を行うことで、Commandパターンが出来上がります。<br /> ## 例 <pre> public class Chef { public static void main(String[] args) { Nabe nabe = new Nabe(); // コマンドオブジェクトを用意する Command water = new WaterCommand(); Command hot = new HotCommand(); Command pasta = new PastaCommand(); Command make = new MakeCommand(); //実験を行う water.execute(nabe); // 鍋に水を入れる hot.execute(nabe); // お湯をわかす pasta.execute(nabe); // パスタを茹でる make.execute(nabe); // お湯を切り、パスタ完成 } } // 水を入れるクラス public class WaterCommand extends Command { public void execute(Nabe nabe) { // 鍋に水を入れる処理 ・・・・ } } // お湯をわかすクラス public class HotCommand extends Command { public void execute(Nabe nabe) { // お湯をわかす処理 ・・・・ } } // パスタを茹でるコマンド・湯を切るコマンドを作成 </pre>
Translate
このブログを検索
ブログアーカイブ
►
2020
(38)
6月 2020
(6)
5月 2020
(10)
4月 2020
(10)
3月 2020
(4)
2月 2020
(5)
1月 2020
(3)
►
2019
(4)
1月 2019
(4)
►
2018
(23)
12月 2018
(3)
4月 2018
(11)
3月 2018
(9)
►
2014
(20)
7月 2014
(3)
1月 2014
(17)
▼
2013
(166)
12月 2013
(15)
11月 2013
(22)
10月 2013
(31)
9月 2013
(26)
8月 2013
(32)
7月 2013
(40)
今週の人気の記事
【まとめ】GWはおうちでぬりえ 鉄道会社公式の電車ぬりえをまとめた
【MySQL】文字列をバイト数で切り取る
【まとめ】おうちでペーパークラフト 鉄道会社公式のペーパークラフトをまとめた
【Trac】 Trac Lightning と Git を連携させる
【PHP】PHPでSFTP接続
フォロワー
On Your Mark
QooQ
0 件のコメント:
コメントを投稿