design_pattern.key

Similar documents
Microsoft PowerPoint ppt

untitled

Microsoft Word - C言語研修 C++編 3.doc

cpp4.dvi

3.1 stdio.h iostream List.2 using namespace std C printf ( ) %d %f %s %d C++ cout cout List.2 Hello World! cout << float a = 1.2f; int b = 3; cout <<

(STL) STL 1 (deta structure) (algorithm) (deta structure) 2 STL STL (Standard Template Library) 2.1 STL STL ( ) vector<int> x; for(int i = 0; i < 10;

ソフトゼミC 第二回 C++の基礎

Prog2_12th

Condition DAQ condition condition 2 3 XML key value

Microsoft PowerPoint pptx

1 C STL(1) C C C libc C C C++ STL(Standard Template Library ) libc libc C++ C STL libc STL iostream Algorithm libc STL string vector l

cpp1.dvi

double 2 std::cin, std::cout 1.2 C fopen() fclose() C++ std::fstream 1-3 #include <fstream> std::fstream fout; int a = 123; fout.open( "data.t

解きながら学ぶC++入門編

11 ソフトウェア工学 Software Engineering デザインパターン DESIGN PATTERNS デザインパターンとは? デザインパターン 過去のソフトウェア設計者が生み出したオブジェクト指向設計に関して, ノウハウを蓄積し 名前をつけ 再利用しやすいようにカタログ化したもの 各デ

Factory Method 2003/07/18 特徴スーパークラスで複数のインスタンスを管理するためのパターン ( スーパークラス ( の型として ) で扱いたいインスタンスが存在するが, スーパークラスではそのインスタンスを生成せずにインターフェースだけを規定し, 各サブクラスでそのインスタン

ALG ppt

1-4 int a; std::cin >> a; std::cout << "a = " << a << std::endl; C++( 1-4 ) stdio.h iostream iostream.h C++ include.h 1-4 scanf() std::cin >>

ohp03.dvi

C のコード例 (Z80 と同機能 ) int main(void) { int i,sum=0; for (i=1; i<=10; i++) sum=sum + i; printf ("sum=%d n",sum); 2

SystemC言語概論

Microsoft PowerPoint - ep_cpp04.ppt

r03.dvi

C 言語経験者のための C++ 入門

Microsoft PowerPoint - chap10_OOP.ppt

とても使いやすい Boost の serialization

VB.NETコーディング標準

file:///D|/C言語の擬似クラス.txt

Microsoft PowerPoint - C++_第1回.pptx

joho07-1.ppt

Exam : 1z1-809-JPN Title : Java SE 8 Programmer II Vendor : Oracle Version : DEMO Get Latest & Valid 1z1-809-JPN Exam's Question and Answers 1 from Ac

いった対策を取ればよいか ということは載っているのですが いまい ち内部まで解説してくれないような印象があります ) Multiple vulnerabilities in Oracle Java 7 before Update 11 allow remote attackers to execut

C , C++ C C++ C++ C cpprefjp - C++ 1 C CUI 2.1 donothing.cpp 1

Java演習(4) -- 変数と型 --


DEMO1 まずはやってみよう アクティビティをダブルクリック 作成 - プロジェクト C# => Workflow CodeActivity をぽとぺ シーケンシャルと ステートマシン それぞれのコ ンソールアプリ あとライブラリがある びっくりマークは足りていないあかし プロパティをみると判別で

1 CUI CUI CUI 1.1 cout cin redirect.cpp #i n c l u d e <s t r i n g > 3 using namespace std ; 5 6 i n t main ( void ) 7 { 8 s t r i n g s ; 10 c

1.3 ( ) ( ) C

4-3- 基 C++ に関する知識 オープンソースシステムのソースを解読する上で C++ の知識は必須であるといえる 本カリキュラムでは まずオブジェクト指向に関する Ⅰ. 概要理解を深め クラスの扱い方について学習し STL を使用してアルゴリズムとデータ構造を実装する方法を学習する Ⅱ. 対象専

基礎計算機演習 実習課題No6

Slide 1

メディプロ1 Javaプログラミング補足資料.ppt

Microsoft PowerPoint - prog04.ppt

Javaの作成の前に

解きながら学ぶC++入門編

超初心者用

programmingII2019-v01

2008chom.pdf

JavaプログラミングⅠ

1

設問 println はそこで指定されている内容を出力して改行するものである. 一方,print は内容を出力して改行しないものである. 下記のプログラムそれぞれについて出力結果がどうなるか回答せよ. 下記のプログラム - を実行すると, fms という文字列が 回表示される. プログラム - vo

PowerPoint Presentation

PowerPoint プレゼンテーション

10/ / /30 3. ( ) 11/ 6 4. UNIX + C socket 11/13 5. ( ) C 11/20 6. http, CGI Perl 11/27 7. ( ) Perl 12/ 4 8. Windows Winsock 12/11 9. JAV

.NETプログラマー早期育成ドリル ~VB編 付録 文法早見表~


新版明解C言語 実践編

基本情報STEP UP演習Java対策

WPF アプリケーションの 多言語切替

Microsoft PowerPoint - class2-OperatorOverLoad.pptx

exec.dvi

新版 明解C++入門編

(Eclipse\202\305\212w\202\324Java2\215\374.pdf)

基礎プログラミング2015

Microsoft PowerPoint - prog03.ppt

グラフの探索 JAVA での実装

1 # include < stdio.h> 2 # include < string.h> 3 4 int main (){ 5 char str [222]; 6 scanf ("%s", str ); 7 int n= strlen ( str ); 8 for ( int i=n -2; i

Microsoft PowerPoint Java基本技術PrintOut.ppt [互換モード]

JavaプログラミングⅠ

2017_08_ICN研究会_印刷用

JavaプログラミングⅠ

基礎プログラミング2015

1) OOP 2) ( ) 3.2) printf Number3-2.cpp #include <stdio.h> class Number Number(); // ~Number(); // void setnumber(float n); float getnumber();

やさしいJavaプログラミング -Great Ideas for Java Programming サンプルPDF

PowerPoint プレゼンテーション

問題 01 以下は コンソールより年齢を入力させ その年齢にあった料金を表示するプログラムである 年齢ごとの金額は以下の通りである 年齢の範囲金額 0 歳以上 6 歳以下 120 円 7 歳以上 65 歳未満 200 円 65 歳以上無料 package j1.exam02; import java

MMXVC_H1

JAVA とテンプレート


Javaセキュアコーディングセミナー2013東京第1回 演習の解説

JavaプログラミングⅠ

2 T 1 N n T n α = T 1 nt n (1) α = 1 100% OpenMP MPI OpenMP OpenMP MPI (Message Passing Interface) MPI MPICH OpenMPI 1 OpenMP MPI MPI (trivial p

Javaプログラムの実行手順

RHEA key

Programming-C-9.key

cpp2.dvi

JavaプログラミングⅠ

JavaプログラミングⅠ

コンパイラ演習 第 7 回

PowerPoint Presentation

デジタル表現論・第4回

Java (5) 1 Lesson 3: x 2 +4x +5 f(x) =x 2 +4x +5 x f(10) x Java , 3.0,..., 10.0, 1.0, 2.0,... flow rate (m**3/s) "flow

PowerPoint プレゼンテーション

全商情報処理検定プログラミング部門 サンプル問題1級解説

新・明解C言語 実践編

グラフと組み合わせ 課題 7 ( 解答例 ) 2013/5/27 1 列挙 n 個の文字の集合 { } S = a, a,, an の全てからなる文字列 つまり同じ文字を含まない 長さ n の文字列を列挙する 方法を考える 1. 何通りの文字列があるかを答えなさい また そのことが正しい

オブジェクト指向プログラミング・同演習 5月21日演習課題

アルゴリズムとデータ構造1

問 次の Fortran プログラムの説明及びプログラムを読んで、設問に答えよ。

10K pdf

Transcription:

#include <iostream> void init(int* ary, int size) for (int i = 0; i < size; ++i) ary[i] = i; void mul10(int* ary, int size) for (int i = 0; i < size; ++i) ary[i] *= 10; void dispary(int* ary, int size) for (int i = 0; i < size; ++i) std::cout << ary[i] << std::endl; int main(void) const int LENGTH = 10; int array[length]; init(array, LENGTH); dispary(array, LENGTH); mul10(array, LENGTH); dispary(array, LENGTH); #include <iostream> class ArrayProcessor public: void doprocess(int* ary, int size) for (int i = 0; i < size; ++i) proc(ary[i], i); protected: // この関数をオーバーライドすることで派生クラスによって処理を切り替えることができる virtual void proc(int& element, int index) = 0; ; class ArrayInitializer : public ArrayProcessor protected: void proc(int& element, int index) element = index; ; class ArrayMultiplier : public ArrayProcessor protected: void proc(int& element, int index) element *= 10; ; class ArrayDisplay : public ArrayProcessor protected: void proc(int& element, int index) std::cout << element << std::endl; ; // 派生クラスの型に合わせてdoProcessの処理が変化 void proc(arrayprocessor& proc, int* ary, int size) proc.doprocess(ary, size); // main int main(void) const int LENGTH = 10; int array[length]; ArrayInitializer init; ArrayDisplay ArrayMultiplier ArrayDetailDisplay dis; multi; del; proc(init, array, LENGTH); proc(dis, array, LENGTH); proc(multi, array, LENGTH); proc(del, array, LENGTH); return 0;

#include <iostream> class Prop public: void propcalc(int* ary, int size) for (int i = 0 ; i<size ; i++) calc(ary[i], i); protected: // この関数をオーバーライドすることで派生クラスによって処理を切り替えることができる virtual void calc(int& element, int index) = 0; ; // ここから派生クラスで実装して使用するときは基底クラスから呼び出す class PropInitializer : public Prop protected: void calc(int& element, int index) element = index; ; class PointSource : public Prop protected: void calc(int& element, int index) element *= 10; ; class WallSource : public Prop protected: void calc(int& element, int index) element *= 100; ; class PropGet : public Prop protected: void calc(int& element, int index) std::cout << element << std::endl; ; // 派生クラスの型に合わせて propcalc の処理が変化 void propagetor(prop& obj_prop, int* ary, int size) obj_prop.propcalc(ary, size); // main int main(void) const int LENGTH = 10; int array[length]; PropInitializer init; PropGet get; WallSource wall; PointSource point; propagetor(init, array, LENGTH); propagetor(wall, array, LENGTH); propagetor(get, array, LENGTH); propagetor(init, array, LENGTH); propagetor(point, array, LENGTH); propagetor(get, array, LENGTH); return 0;

#include <iostream> class Prop public: void propcalc(int* ary, int size) for (int i = 0 ; i<size ; i++) calc_src(ary[i], i); protected: // この関数をオーバーライドすることで派生クラスによって処理を切り替えることができる virtual void calc_src(int& element, int index) = 0; ; // ここから派生クラスで実装して使用するときは基底クラスから呼び出す class PropInitializer : public Prop ; class PointSource : public Prop protected: void calc_src(int& element, int index) std::cout<<"calc point src" << std::endl; element *= 10; ; class WallSource : public Prop protected: void calc_src(int& element, int index) std::cout<<"calc wall src" << std::endl; element *= 100; ; // context class によってインターフェイス (Prop) にアクセス class Context public: // コンストラクタ \ \ Context(Prop* obj_prop, int size) obj_prop_ = obj_prop; size_ = size; array_ = new int[size_](); // デストラクタ ~Context() delete [] array_; free (obj_prop_;) void init() for (int i =0 ; i< size_ ;i ++) array_[i] = i; void PropGet() for(int i =0; i<size_ ;i ++) std::cout << array_[i] << std::endl; void calc() obj_prop_->propcalc(array_,size_); private: Prop* obj_prop_; int* array_; int size_; // 派生クラスの型に合わせて propcalc の処理が変化 ; // main int main(void) const int LENGTH = 10; Context* obj1 = new Context(new WallSource(),LENGTH); Context* obj2 = new Context(new PointSource(),LENGTH); obj1->init(); obj1->calc(); obj2->init(); obj2->calc(); obj1->propget(); obj2->propget(); return 0;

#include <iostream> #include <string> /* Implemented interface. */ class AbstractInterface public: virtual void somefunctionality() = 0; ; /* Interface for internal implementation that Bridge uses. */ class ImplementationInterface public: virtual void anotherfunctionality() = 0; ; /* The Bridge */ class Bridge : public AbstractInterface protected: ImplementationInterface* implementation; public: Bridge(ImplementationInterface* backend) implementation = backend; ; class UseCase1 : public Bridge public: UseCase1(ImplementationInterface* backend) : Bridge(backend) void somefunctionality() std::cout << "UseCase1 on "; implementation->anotherfunctionality(); ; class UseCase2 : public Bridge public: UseCase2(ImplementationInterface* backend) : Bridge(backend) void somefunctionality() std::cout << "UseCase2 on "; implementation->anotherfunctionality(); ; /* Different special cases of the interface. */ /* Different background implementations. */ class Windows : public ImplementationInterface public: void anotherfunctionality() std::cout << "Windows :-" << std::endl; ; class Linux : public ImplementationInterface public: void anotherfunctionality() std::cout << "Linux :-)" << std::endl; ; int main() AbstractInterface *usecase = 0; ImplementationInterface *oswindows = new Windows; ImplementationInterface *oslinux = new Linux; /* First case */ usecase = new UseCase1(osWindows); usecase->somefunctionality(); usecase = new UseCase1(osLinux); usecase->somefunctionality(); /* Second case */ usecase = new UseCase2(osWindows); usecase->somefunctionality(); usecase = new UseCase2(osLinux); usecase->somefunctionality(); return 0; UseCase1 on Windows :- UseCase1 on Linux :-) UseCase2 on Windows :- UseCase2 on Linux :-)

#include <iostream> #include <string> /* Implemented interface. */ class AbstractInterface public: virtual void somefunctionality() = 0; ; /* Interface for internal implementation that Bridge uses. */ class ImplementationInterface public: virtual void anotherfunctionality() = 0; ; /* The Bridge */ class Bridge : public AbstractInterface protected: ImplementationInterface* implementation; public: Bridge(ImplementationInterface* backend) implementation = backend; ; /* Different special cases of the interface. */ class UseCase1 : public Bridge public: UseCase1(ImplementationInterface* backend) : Bridge(backend) void somefunctionality() std::cout << "UseCase1 on "; implementation->anotherfunctionality(); ; class UseCase2 : public Bridge /* Different background implementations. */ class Windows : public ImplementationInterface public: void anotherfunctionality() std::cout << "Windows :-" << std::endl; ; class Linux : public ImplementationInterface public: void anotherfunctionality() std::cout << "Linux :-)" << std::endl; ; int main() AbstractInterface *usecase = 0; ImplementationInterface *oswindows = new Windows; ImplementationInterface *oslinux = new Linux; /* First case */ usecase = new UseCase1(osWindows); usecase->somefunctionality(); usecase = new UseCase1(osLinux); usecase->somefunctionality(); /* Second case */ usecase = new UseCase2(osWindows); usecase->somefunctionality(); usecase = new UseCase2(osLinux); return 0; usecase->somefunctionality(); public: UseCase2(ImplementationInterface* backend) : Bridge(backend) void somefunctionality() std::cout << "UseCase2 on "; implementation->anotherfunctionality(); ;

#include <iostream> class Singleton public: // 唯一のアクセス経路 static Singleton* GetInstance() static Singleton instance; // 唯一のインスタンス return &instance; // あとは このクラス自身が必要なメンバを定義する private: // 生成やコピーを禁止する Singleton() Singleton(const Singleton& rhs); Singleton& operator=(const Singleton& rhs); ; int main() Singleton* obj1 = obj1->getinstance(); Singleton* obj2 = obj2->getinstance(); if(obj1==obj2) std::cout << "same instance"<<std::endl; return 0;

#include <cstring> #include <iostream> using namespace std; //Adaptee class Banner public : Banner(string str) this->string_ = str; void ShowWithParen() cout << string_.c_str() << endl; void ShowWithAster() cout << "*" << string_.c_str() << "*" << endl; private : string string_; ; //Target(interface) class Print public : virtual ~Print(); virtual void PrintWeak() = 0; virtual void PrintStrong() = 0; ; //Adapter class PrintBanner : public Print public : ~PrintBanner() delete banner_; PrintBanner(string str) banner_ = new Banner(str); void PrintWeak() banner_->showwithparen(); void PrintStrong() banner_->showwithaster(); private : Banner * banner_; ; int main() Print *p = new PrintBanner("Hello"); p->printweak(); p->printstrong(); delete p; getchar(); return 0;