当前位置: 首页 > news >正文

厦门做网站多少百度竞价是什么意思?

厦门做网站多少,百度竞价是什么意思?,成都倒闭的网站建设公司名单,南宁手机建站公司介绍 享元模式运用共享技术有效地支持大量细粒度对象的复用。系统只使用少量的对象#xff0c;而这些对象都很相似#xff0c;状态变化很小#xff0c;可以实现对象的多次复用。由于享元模式要求能够共享的对象必须是细粒度对象#xff0c;因此它又称为轻量级模式#xff…介绍 享元模式运用共享技术有效地支持大量细粒度对象的复用。系统只使用少量的对象而这些对象都很相似状态变化很小可以实现对象的多次复用。由于享元模式要求能够共享的对象必须是细粒度对象因此它又称为轻量级模式是一种对象结构型模式。 实现 myclass.h // // Created by yuwp on 2024/1/12. //#ifndef DESIGNPATTERNS_MYCLASS_H #define DESIGNPATTERNS_MYCLASS_H#include iostream #include unordered_mapclass Flyweight { // 享元抽象类 public:Flyweight(const std::string in);virtual void operation(const std::string out) 0;const std::string getMIn() const;private:std::string m_in; };class ConcreteFlyweight : public Flyweight { // 具体享元类 public:ConcreteFlyweight(const std::string in);void operation(const std::string out) override; };class FlyweightFactory { // 配合工厂模式使用享元工厂类 public:~FlyweightFactory();Flyweight *getFlyweight(const std::string key); private:std::unordered_mapstd::string, Flyweight * m_flyweights; };#endif //DESIGNPATTERNS_MYCLASS_Hmyclass.cpp // // Created by yuwp on 2024/1/12. //#include myclass.hFlyweight::Flyweight(const std::string in) {m_in in; }const std::string Flyweight::getMIn() const {return m_in; }ConcreteFlyweight::ConcreteFlyweight(const std::string in) : Flyweight(in) {}void ConcreteFlyweight::operation(const std::string out) {std::cout 内部状态: getMIn() , 外部状态: out std::endl; }FlyweightFactory::~FlyweightFactory() {for (auto it : m_flyweights) {if (it.second) {delete it.second;}} }Flyweight* FlyweightFactory::getFlyweight(const std::string key) {auto it m_flyweights.find(key);if (it ! m_flyweights.end()) {return it-second;} else {Flyweight *flyweight new ConcreteFlyweight(key);m_flyweights.insert(std::make_pair(key, flyweight));return flyweight;} } main.cpp #include iostream #include mutex #include myclass.hint main() {FlyweightFactory *factory new FlyweightFactory();auto fly1 factory-getFlyweight(a);auto fly2 factory-getFlyweight(b);auto fly3 factory-getFlyweight(a);fly1-operation(1);fly2-operation(2);fly3-operation(3);delete factory;return 0; } 总结 优点 1. 可以极大减少内存中对象的数量使得相同或相似对象在内存中只保存一份从而可以节约系统资源提高系统性能。 2. 享元模式的外部状态相对独立而且不会影响其内部状态从而使得享元对象可以在不同的环境中被共享。 缺点 1. 享元模式需要分离出内部状态和外部状态从而使得系统变得复杂这使得程序的逻辑复杂化。 2. 为了使对象可以共享享元模式需要将享元对象的部分状态外部化而读取外部状态将使得运行时间变长。 适用场景 1. 一个系统有大量相同或者相似的对象造成内存的大量耗费。 2. 对象的大部分状态都可以外部化可以将这些外部状态传入对象中。 3. 在使用享元模式时需要维护一个存储享元对象的享元池而这需要耗费一定的系统资源。因此在需要多次重复使用同一享元对象时才值得使用享元模式。 练习 myclass.h // // Created by yuwp on 2024/1/12. //#ifndef DESIGNPATTERNS_MYCLASS_H #define DESIGNPATTERNS_MYCLASS_H#include iostream #include unordered_mapclass Flyweight { // 享元抽象类 public:Flyweight(const std::string in);virtual void display(const std::string out) 0;const std::string getMIn() const;private:std::string m_in; };class PictureFlyweight : public Flyweight { // 具体享元类 public:PictureFlyweight(const std::string in);void display(const std::string out) override; };class AnimationFlyweight : public Flyweight { // 具体享元类 public:AnimationFlyweight(const std::string in);void display(const std::string out) override; };class VideoFlyweight : public Flyweight { // 具体享元类 public:VideoFlyweight(const std::string in);void display(const std::string out) override; };class FlyweightFactory { // 配合工厂模式使用享元工厂类 public:~FlyweightFactory();Flyweight *getFlyweight(const std::string key);static FlyweightFactory *getInstance(); private:FlyweightFactory();std::unordered_mapstd::string, Flyweight * m_flyweights; };#endif //DESIGNPATTERNS_MYCLASS_Hmyclass.cpp // // Created by yuwp on 2024/1/12. //#include myclass.hFlyweight::Flyweight(const std::string in) {m_in in; }const std::string Flyweight::getMIn() const {return m_in; }PictureFlyweight::PictureFlyweight(const std::string in) : Flyweight(in) {}void PictureFlyweight::display(const std::string out) {std::cout out , getMIn() std::endl; }AnimationFlyweight::AnimationFlyweight(const std::string in) : Flyweight(in) {}void AnimationFlyweight::display(const std::string out) {std::cout out , getMIn() std::endl; }VideoFlyweight::VideoFlyweight(const std::string in) : Flyweight(in) {}void VideoFlyweight::display(const std::string out) {std::cout out , getMIn() std::endl; }FlyweightFactory::FlyweightFactory() {}FlyweightFactory* FlyweightFactory::getInstance() {static FlyweightFactory *factory new FlyweightFactory();return factory; }FlyweightFactory::~FlyweightFactory() {for (auto it : m_flyweights) {if (it.second) {delete it.second;}} }Flyweight* FlyweightFactory::getFlyweight(const std::string key) {auto it m_flyweights.find(key);if (it ! m_flyweights.end()) {return it-second;} else {Flyweight *flyweight nullptr;if (key 图片) {flyweight new PictureFlyweight(key);} else if (key 动画) {flyweight new AnimationFlyweight(key);} else if (key 视频) {flyweight new VideoFlyweight(key);}m_flyweights.insert(std::make_pair(key, flyweight));return flyweight;} } main.cpp #include iostream #include mutex #include myclass.hint main() {FlyweightFactory *factory FlyweightFactory::getInstance();factory-getFlyweight(图片)-display(1);factory-getFlyweight(动画)-display(2);factory-getFlyweight(视频)-display(3);factory-getFlyweight(图片)-display(4);return 0; }
http://www.hkea.cn/news/14488111/

相关文章:

  • 北京公司网站建wordpress可以做淘宝
  • 婚纱网站怎么做seo网站备案 主办单位
  • 物流怎么弄网站网站建设制作模板网站怎么做
  • wordpress爱好者论坛重庆网站建设seo公司
  • 微网站如何建设网站建设361
  • 青州建网站本地运行wordpress
  • 经典网站设计网站保定百度首页优化
  • 网站建设谈单情景对话用易语言做攻击网站软件下载
  • 淘宝指数网站网站开发算软件开发吗
  • 在小网站上做点击广告wordpress投递文章插件
  • 建设银行流水账网站查询网站没有在工信部备案
  • 网站云模板网站开发相关会议
  • 沈阳网站建设模块维护目前最好用的网络管理软件
  • 成都网页编辑器开发英文网站seo推广
  • 怎么做网站zwnet通河县机场建设网站
  • 公司企业网站有哪些虚拟空间怎么做网站目录指向
  • 小网站做几个关键词生产管理软件app
  • 10个免费网站重庆建设工程招标投标交易信息网
  • 价格便宜的网站建设高校网站建设规范
  • 北京网站优化对策如何给网站做地图
  • 案例学 网页设计与网站建设班级优化大师官网下载
  • 山西疾控最新通告今天汕头网络推广seo渠道
  • 如何给网站更换域名市场调研报告500字
  • tomcat做公司网站如何查找做网站的服务商
  • 小说网站做编辑济南网站建设制作
  • 营销型网站建设价值福建省建设工程继续教育网站
  • asp网站搭建软件婚庆公司一条龙项目
  • 服务器怎么用数据库建设网站免费做图片的网站有哪些
  • 镇江网站关键字优化如何外贸公司做网站该去哪里找
  • 南宁网站开发培训php 怎么做视频网站