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

房地产网站模板外发加工会计分录

房地产网站模板,外发加工会计分录,2022最新的旅游资讯,怎么建个免费英文网站享元模式 1.1 分类 #xff08;对象#xff09;结构型 1.2 提出问题 做一个车管所系统#xff0c;将会产生大量的车辆实体#xff0c;如果每一个实例都保存自己的所有信息#xff0c;将会需要大量内存#xff0c;甚至导致程序崩溃。 1.3 解决方案 运用共享技术有效…享元模式 1.1 分类 对象结构型 1.2 提出问题 做一个车管所系统将会产生大量的车辆实体如果每一个实例都保存自己的所有信息将会需要大量内存甚至导致程序崩溃。 1.3 解决方案 运用共享技术有效的支持大量细粒度的对象。 1.4 实现类图 享元模式只是一种优化。只有存在大量类似对象销毁内存的情况才考虑使用。享元Flyweight类包含原始对象中部分能在多个对象中共享的状态。享元中存储的状态被称为“内在状态”。传递给享元方法的状态被称为“外在状态”。上下文Context类包含原始对象中各不相同的外在状态。上下文与享元对象组合在一起就能表示原始对象的全部状态。通常情况下原始对象的行为保留在享元类中。因此调用享元方法必须提供部分外在状态作为参数。但也可将行为移动到上下文类中将连入的享元作为单纯的数据对象。客户端Client负责计算或存储享元的外在状态。在客户端看来享元是一种可在运行时进行配置的模板对象具体的配置方式为向其方法中传入一些上下文数据参数。享元工厂Flyweight Factory会对已有享元的缓存池进行管理。有了工厂后客户端就无需直接创建享元只需调用工厂并向其传递目标享元的一些内在状态即可。工厂会根据参数在之前已创建的享元中进行查找如果找到满足条件的享元就将其返回如果没有找到就根据参数新建享元。 1.5 示例代码 #include iostream #include string #include unordered_mapusing std::string; //内部状态 struct SharedState {string m_brand;string m_model;string m_color;SharedState(const string brand, const string model, const string color):m_brand(brand), m_model(model), m_color(color) {}friend std::ostream operator(std::ostream os, const SharedState ss) {return os [ ss.m_brand , ss.m_model , ss.m_color ];} }; //外部状态 struct UniqueState {std::string m_owner;std::string m_plates;UniqueState(const std::string owner, const std::string plates): m_owner(owner), m_plates(plates) {}friend std::ostream operator(std::ostream os, const UniqueState us) {return os [ us.m_owner , us.m_plates ];} };//享元存放共享状态内部状态 class Flyweight { private:SharedState m_sharedState; public:Flyweight(const SharedState sharedState) : m_sharedState(sharedState) {}//使用的时候使用外部状态作为参数对整个context做出操作void operation(UniqueState uniqueState) const {std::cout Flyweight:显示内部状态 m_sharedState ),显示外部状态 uniqueState )\n;} }; //享元工厂 class FlyweightFactory { private:std::unordered_mapstring, Flyweight m_Flyweights;string getKey(const SharedState ss) const {return ss.m_brand _ ss.m_model _ ss.m_color;} public:FlyweightFactory(std::initializer_listSharedState share_states) {for (const SharedState ss : share_states) {m_Flyweights.insert({ getKey(ss),Flyweight(ss) });}}Flyweight* getFlyWeight(const SharedState shared_state) {string key getKey(shared_state);if (m_Flyweights.find(key) m_Flyweights.end()) {std::cout FlyweightFactory:没有找到需要的享元创建一个新的。\n;m_Flyweights.insert({ key,shared_state });} else {std::cout FlyweightFactory:返回一个现有的享元。\n;}return m_Flyweights.at(key);}void listFlyWeights() const {int count m_Flyweights.size();std::cout \nFlyweightFactory:我有 count 个享元\n;for (std::pairstd::string, Flyweight item : m_Flyweights) {std::cout item.first \n;}} }; //上下文 class CarInfoContext { private:Flyweight* m_flyWeight nullptr;//内部状态UniqueState m_uniqueState;//外部状态 public:CarInfoContext(Flyweight* flyWeight, const UniqueState * unique_state) :m_flyWeight(flyWeight), m_uniqueState(*unique_state) {}void operation() {m_flyWeight-operation(m_uniqueState);} }; //Client class PoliceCarDatabase { private:std::listCarInfoContext* carInfoDatabase; public:~PoliceCarDatabase() {for (auto item : carInfoDatabase)delete item;}void addCarToPoliceDatabase(FlyweightFactory ff,const string owner, const string plates,const string brand, const string model, const string color) {std::cout \n客户端添加车辆信息到数据库。\n;Flyweight* flyWeight ff.getFlyWeight({ brand, model, color });//内部状态UniqueState uniqueState(owner, plates);//外部状态carInfoDatabase.push_back(new CarInfoContext(flyWeight, uniqueState));std::cout \n客户端数据库当前状态\n;for (auto item : carInfoDatabase) {item-operation();}} }; int main() {FlyweightFactory factory({SharedState(奔驰,GLC,白色),SharedState(奥迪,A7,黑色),SharedState(宝马,X1,白色)});factory.listFlyWeights();PoliceCarDatabase database;database.addCarToPoliceDatabase(factory,阿西拜, 赣ABC888, 奔驰, GLC, 白色);factory.listFlyWeights();database.addCarToPoliceDatabase(factory,阿西拜, 赣ABC999, 比亚迪, 唐EV, 蓝色);database.addCarToPoliceDatabase(factory,阿西拜, 赣ABC666, 奔驰, GLC, 白色);factory.listFlyWeights(); }1.6 举个栗子 享元模式能有效减少在画布上渲染数百万个树状 对象时所需的内存。 1.7 总结 优点如果程序中有很多相似对象那么你将可以节省大量内存。缺点可能需要牺牲执行速度来换取内存因为他人每次调用享元方法时都需要重新计算部分情景数据。
http://www.hkea.cn/news/14459398/

相关文章:

  • 一台服务器做两个网站吗竹林wordpress主题
  • 网站开发 自学快速排名优化系统
  • 做网站好听的域名农村创业好项目
  • 我的世界做皮肤壁纸网站高端网站建设天软科技
  • 大网站怎样选域名网络推广好做吗?
  • 网站域名价值查询计算机网站设计论文
  • 权威行业网站建设公司汕头澄海招聘网
  • 优惠卷网站怎么做推广wordpress加skype
  • 制作logo的网站厦门短视频代运营公司
  • asp.net网站开发实例教程wordpress主题+清新
  • 广州网站建设系统国外知名平面设计网站
  • 西安网站建设网站建设视频制作图片
  • 银行网站 设计方案网站建设捌金手指花总十四
  • 东莞专业网站制作设计wordpress+主题+引入js
  • 中国古建筑网站网页设计课程期末总结
  • 平安网站建设工作总结自建域名
  • 站长工具seo综合查询 正品蓝导航搭建个网站多少钱
  • 网站怎样优化seowordpress plugins权限
  • 三种常用的网站设计软件公司网站管理规定
  • 创建本地网站网站改版销售话术
  • 网站建设找业主签字模板企业邮箱查询
  • 谷歌seo网站建设泰安人才网app
  • 怎么建设一个淘宝客网站湖北建设执业注册管理中心网站
  • 一个具体网站的seo优化线上营销培训
  • flask做网站工具怎么在word添加wordpress
  • 网站建设目的意义软件开发工作
  • 网站平台设计费用西安市城乡建设管理局网站
  • 南昌网站建设在哪里wordpress运行php文件下载
  • 做网站php的作用社保代缴网站开发
  • 广东省网站备案系统宝安网站制作网站建设