設計模式--享元模式實現C++

/*********************************
*設計模式--享元模式實現
*C++語言
*Author:WangYong
*Blog:http://www.cnblogs.com/newwy
********************************/
#include <iostream>
#include <cassert>
#include <vector>
#include <string>
using namespace std;
class Flyweight
{public:virtual ~Flyweight(){}virtual void Operation(const string & extrinsicState){}string GetIntrinsicState(){return this->_intrinsicState;}protected:Flyweight(string intrinsicState){this->_intrinsicState = _intrinsicState;}private:string _intrinsicState;
};
class ConcreteFlyweight:public Flyweight
{public:ConcreteFlyweight(string intrinsicState):Flyweight(intrinsicState){cout<<"ConcreteFlyweight Build ...."<<intrinsicState<<endl;}~ConcreteFlyweight(){}void Operation(const string & extrinsicState){cout<<"ConcreteFlyweight:內蘊"<<this->GetIntrinsicState()<<"ConcreteFlyweight:外蘊"<<extrinsicState<<endl;}
};
class FlyweightFactory
{public:FlyweightFactory(){}~FlyweightFactory(){}Flyweight * GetFlyweight(const string &key){vector<Flyweight *>::iterator it = _fly.begin();for(;it != _fly.end(); it++){if( (*it)->GetIntrinsicState() == key)cout<<"already created by users..."<<endl;return *it;}Flyweight *fn = new ConcreteFlyweight(key);_fly.push_back(fn);return fn;	}private:vector<Flyweight*> _fly;
};
int main()
{FlyweightFactory *fc = new FlyweightFactory();Flyweight * fw1 = fc->GetFlyweight("hello");Flyweight * fw2 = fc->GetFlyweight("world!");Flyweight * fw3 = fc->GetFlyweight("hello");
}

轉載于:https://www.cnblogs.com/newwy/archive/2010/10/18/1855224.html

本文來自互聯網用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務,不擁有所有權,不承擔相關法律責任。
如若轉載,請注明出處:http://www.pswp.cn/news/275842.shtml
繁體地址,請注明出處:http://hk.pswp.cn/news/275842.shtml
英文地址,請注明出處:http://en.pswp.cn/news/275842.shtml

如若內容造成侵權/違法違規/事實不符,請聯系多彩編程網進行投訴反饋email:809451989@qq.com,一經查實,立即刪除!

相關文章

安卓加載asset中的json文件_Android解析Asset目錄下的json文件

在app module中的src/main/assets目錄下我們準備了兩個json文件&#xff1a;destination.json如下&#xff1a;{"main/tabs/sofa": {"isFragment": true,"asStarter": false,"needLogin": false,"pageUrl": "main/tabs…

一文搞懂 Promise、Genarator、 Async 三者的區別和聯系

非985/211大學畢業&#xff0c;軟件工程專業&#xff0c;前端&#xff0c;坐標&#xff1a;北京工作三年多&#xff0c;第一家人數 30 多人的創業公司&#xff0c;1 年多。第二家屬于前端技術不錯的公司&#xff0c;2 年多。01我是一個喜歡在技術領域“折騰”的人&#xff0c;技…

閉包,sync使用細節

代碼 先看代碼如下&#xff1a; func main() {var a []intfor i : 0; i < 100; i {go func() {a append(a, i)}()}time.Sleep(2 * time.Second)fmt.Println(a) } 這段測試代碼是想要一個元素為0到100的切片&#xff0c;但是這一小段代碼隱藏了很多的問題。 閉包函數 先看這…

dynamic 儀表板_儀表板完成百萬美元交易

dynamic 儀表板問題 (The Problem) Anybody dealing with tech products and data-focused services runs into the same fundamental problem: what you do is technical but non-technical people control the budget. In other words:任何處理高科技產品和以數據為中心的服務…

checkStyle -- 代碼風格一致

download page: http://sourceforge.net/project/showfiles.php?group_id80344&package_id107587 轉載于:https://www.cnblogs.com/xuqiang/archive/2010/10/26/1953431.html

在線VS Code閱讀源碼神器 github1s

大家好&#xff0c;我是若川。github1s大部分人知道了&#xff0c;但還是有一部分不知道。我在掘金發過沸點和知乎發過想法還是有挺多人不知道&#xff0c;所以再發公眾號推薦下。點擊下方卡片關注我、加個星標。學習源碼整體架構系列、年度總結、JS基礎系列近日&#xff0c;一…

lenze變頻器怎么更改地址_英威騰變頻器GD300維修

英威騰變頻器GD300維修英威騰變頻器GD300維修41. 問題&#xff1a;變頻器跟PLC采用485通訊不上答&#xff1a;1.檢查變頻器的通訊地址是否正確&#xff0c;如果采用通訊啟動&#xff0c;檢查P0.01是否為1&#xff0c;如果通過通訊設定頻率&#xff0c;檢查P0.068&#xff0c;P0…

代碼設計的基礎原則_設計原則:良好設計的基礎

代碼設計的基礎原則As designers, it’s our goal to pass information in the most pleasing way possible. Starting out, there’s a wealth of literature to read and videos to watch that can get quite overwhelming to take in at a glance. People take different ro…

SQL根據細粒度為天的查詢

當我們集成了一些前端框架&#xff0c;在某些展示頁面上往往具有某些查詢條件。而這其中日期查詢的處理又較為麻煩&#xff0c;此處&#xff0c;我羅列了一種當前臺上傳了一種默認的date格式的日期查詢數據至后臺未經Controller或Service層處理直接在SQL中處理的一種方式——即…

企業生產經營相關英文及縮寫之(11)--Genenic 普通書寫

Genenic 普通書寫 ASAP As soon as possible 盡早 BCC Blink Carbon Copy 無信頭抄送&#xff0c;無信頭副本 BR Best Regards 最誠致的問候 BTW By the way 順便問一下 CC Carbon Copy …

java金額類型_Java中存儲金額用什么數據類型?

很早之前, 記得一次面試, 面試官問存儲金錢用什么數據類型? 當時只知道8種數據類型(boolean, byte, short, int, long, float, double, char)的我, 回答了double, 因為我覺得double是雙精度類型, 最適合, 但是面試官告訴我應該用BigDecimal! 最近在做支付的項目, 才對這種數據…

信息技術與信息革命

信息資源管理學什么 圍繞 信息這份戰略資源&#xff0c;從信息資源的管理角度出發&#xff0c;以信息系統為主要研究對象&#xff0c; 研討了信息系統規劃&#xff0c;信息系統開發 信息系統的內容&#xff0c;信息系統安全以及信息資源管理中 涉及的法律法規 知識框架 信息技術…

React Hooks 不知道怎么學?看這篇

大家好&#xff0c;我是若川。最近跟朋友聊技術&#xff0c;發現越來越多的大廠&#xff0c;都優先考慮用 React 做項目&#xff0c;在面試中也經常會考察對 React Hooks 的理解。其實&#xff0c;我一直覺得&#xff0c;React 才是前端的正確打開方式。當然&#xff0c;并不是…

數字與企鵝的戰爭,看周紅衣的高明之處

本文非原創&#xff0c;轉自月光    360與QQ最近的一輪大戰已經接近尾聲&#xff0c;毫無疑問的是&#xff0c;360在這一輪對決中以勝利告終。這場戰爭持續了整整一個月零兩天&#xff0c;先后經歷了幾次小小的高潮&#xff0c;最終周鴻祎祭出絕招&#xff0c;秒殺群雄&#…

ui原型設計工具_UI設計師的工具包,用于專業模型,原型和產品插圖

ui原型設計工具This is a followup to my previous article 這是我上一篇文章的后續 visual tools for UX Designers視覺工具Tools don’t make designs better– you do! It doesn’t matter if you paid a lot of money for the latest software, or if you simply have a p…

java wsdl xfire_java調用wsdl xfire和cxf兩種方式

xfire 如下&#xff1a;String spID "";String password "";String accessCode "";String content "";String mobileString "";String url "";String operateName "Submit";Object[] object newObject…

請求與響應

HTTP 請求與響應 HTTP 請求的組成的四部分&#xff1a; 1 動詞 路徑 協議/版本2 Key1: value12 Key2: value22 Key3: value32 Content-Type: application/x-www-form-urlencoded2 Host: www.baidu.com2 User-Agent: curl/7.54.034 要上傳的數據 關于以上各部分內容的碎碎念&…

前端 Offer 提速:如何寫出有亮點的簡歷

大家好&#xff0c;我是若川。今天推薦一篇8年工作經驗字節大佬的文章&#xff0c;如何寫出有亮點的簡歷。可以收藏常看。點擊下方卡片關注我、加個星標。學習源碼整體架構系列、年度總結、JS基礎系列先來個靈魂拷問&#xff1a;「你與他人相比&#xff0c;有什么能形成明顯區分…

2008中的membership profile操作(轉)

<profile > <properties> <add name"jimmy" /> </< span>properties> </< span>profile> 然后就那么簡單,后臺就能通過Profile拿到: Profile.jimmy "Pumpkin Ravioli"; 然后~通過這種方式就跟Session一樣&a…

css網格_一個CSS網格可以全部統治

css網格The case for using one CSS grid for your entire website在整個網站上使用一個CSS網格的情況 CSS網格與Flexbox (CSS Grid vs Flexbox) In the dark ages, we used table, a few years ago we used float and before today most of us used flex . Of course, these …