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

如何选择网站空间seo培训机构排名

如何选择网站空间,seo培训机构排名,北京网站制作,小程序可以做网站吗概念 享元模式是一种结构型设计模式,他摒弃了在每个对象中保存所有数据的方式,通过共享多个对象所共有的相同状态,让你能在有限的内存容量中载入更多对象。享元模式将原始类中的数据分为内在状态数据和外在状态数据。 内在状态:就…

概念

享元模式是一种结构型设计模式,他摒弃了在每个对象中保存所有数据的方式,通过共享多个对象所共有的相同状态,让你能在有限的内存容量中载入更多对象。享元模式将原始类中的数据分为内在状态数据和外在状态数据。
内在状态:就是不变的在各个对象中重复使用的成员变量。
外在状态:每个对象各自不同的情景的数据成员变量。会通过外部函数进行修改。

适用场景

在程序中支持大量的对象且没有足够的内存容量时使用享元模式

使用方式

1、分析代码需求,将成员变量分解为两个部分,

内在状态:就是不变的在各个对象中重复使用的成员变量。

外在状态:每个对象各自不同的情景的数据成员变量。会通过外部函数进行修改。

将原始对象拆分为情景类和享元类。

2、创建一个享元类,用于存储内在状态成员变量。

3、创建一个情景类,用于存储外在状态的成员变量。并在这个情景类中创建一个享元类的引用。

4、创建一个享元工厂类,创建需要的享元对象,如果没有就创建一个新的享元对象并添加到容器或者工厂中。

5、当创建完整的数据类的时候可以去容器或者工厂中寻找有没有需要的享元对象,有的话直接拿出来用,没有的话创建新的。

类关系结构

在这里插入图片描述

代码示例

#include "XiangYuanMoShi.h"int main()
{std::cout << "欢迎东哥来到设计模式的世界!\n";//创建一个size = 2,color= 绿色,伤害 = 100的子弹BulletShareFactory factory;Bullet* bullet = new Bullet();bullet->x = 100;bullet->y = 100;bullet->m_share = factory.getBulletShare(100, "绿色","100");bullet->display();Bullet* bullet2 = new Bullet();bullet2->x = 200;bullet2->y = 200;bullet2->m_share = factory.getBulletShare(100, "绿色", "100");bullet2->display();
}
#pragma once
#include <string>
#include <vector>
#include <iostream>
using namespace std;
//假设有个场景,在一个游戏中我们需要设置子弹的样式,在显示的过程中我们要随时修改子弹的位置
//和方向。子弹有不同的类型(大小、颜色、伤害)//享元类
class BulletShare
{
public:BulletShare() {}~BulletShare() {}//内在数据int size;string color;string hurt;
};//情景类
class Bullet {
public:Bullet() {}~Bullet() {}//外在数据int x;int y;int direction;//内在对象引用BulletShare* m_share = nullptr;void display() {cout << "x:" << x << "   y:" << y<<"   size:" << m_share->size << endl;cout << "share地址:" << m_share << endl;}
};//享元工厂类
class BulletShareFactory {
public:BulletShareFactory() {}~BulletShareFactory() {}//享元类数据存储vector<BulletShare*> m_vBulletShare;BulletShare* getBulletShare(int size, string color, string hurt) {BulletShare* share = nullptr;if (m_vBulletShare.size() > 0) {for (int i = 0; i < m_vBulletShare.size(); i++) {if (m_vBulletShare[i]->color == color &&m_vBulletShare[i]->size == size &&m_vBulletShare[i]->hurt == hurt) {share = m_vBulletShare[i];break;}}}if(!share){share = new BulletShare();if (share) {share->color = color;share->hurt = hurt;share->size = size;m_vBulletShare.push_back(share);}}return share;}
};

文章转载自:
http://ostracise.c7622.cn
http://sixain.c7622.cn
http://mesocratic.c7622.cn
http://pinder.c7622.cn
http://omnificent.c7622.cn
http://auscultative.c7622.cn
http://suppressant.c7622.cn
http://alewife.c7622.cn
http://citron.c7622.cn
http://ringling.c7622.cn
http://purplish.c7622.cn
http://plasterboard.c7622.cn
http://lido.c7622.cn
http://penninite.c7622.cn
http://crackling.c7622.cn
http://frig.c7622.cn
http://dispersedness.c7622.cn
http://fearful.c7622.cn
http://effort.c7622.cn
http://polyembryony.c7622.cn
http://commandeer.c7622.cn
http://torgoch.c7622.cn
http://amethopterin.c7622.cn
http://norsteroid.c7622.cn
http://babiroussa.c7622.cn
http://codebreaker.c7622.cn
http://conserve.c7622.cn
http://carburant.c7622.cn
http://sisterly.c7622.cn
http://undoubled.c7622.cn
http://ragingly.c7622.cn
http://souchong.c7622.cn
http://mend.c7622.cn
http://drifter.c7622.cn
http://tracklayer.c7622.cn
http://embryologist.c7622.cn
http://dysphagia.c7622.cn
http://irresolutely.c7622.cn
http://ropey.c7622.cn
http://bursary.c7622.cn
http://climax.c7622.cn
http://midnightly.c7622.cn
http://ribbonman.c7622.cn
http://conductor.c7622.cn
http://timesaver.c7622.cn
http://marmoset.c7622.cn
http://conscientious.c7622.cn
http://pantelegraph.c7622.cn
http://chorister.c7622.cn
http://missourian.c7622.cn
http://homemaker.c7622.cn
http://excoriation.c7622.cn
http://technify.c7622.cn
http://paling.c7622.cn
http://believable.c7622.cn
http://crankshaft.c7622.cn
http://matraca.c7622.cn
http://of.c7622.cn
http://kentucky.c7622.cn
http://unimportance.c7622.cn
http://lipsticky.c7622.cn
http://unhysterical.c7622.cn
http://carpentaria.c7622.cn
http://sundriesman.c7622.cn
http://rift.c7622.cn
http://monotrematous.c7622.cn
http://zoomorphic.c7622.cn
http://hydrofluoric.c7622.cn
http://carley.c7622.cn
http://citic.c7622.cn
http://shoplifter.c7622.cn
http://octameter.c7622.cn
http://cholecystitis.c7622.cn
http://backdrop.c7622.cn
http://energumen.c7622.cn
http://perceptual.c7622.cn
http://easier.c7622.cn
http://slummer.c7622.cn
http://spirituelle.c7622.cn
http://dpn.c7622.cn
http://dusting.c7622.cn
http://andrew.c7622.cn
http://spleeny.c7622.cn
http://disgorge.c7622.cn
http://plumose.c7622.cn
http://chanticleer.c7622.cn
http://ossific.c7622.cn
http://eutherian.c7622.cn
http://uther.c7622.cn
http://hanepoot.c7622.cn
http://next.c7622.cn
http://bast.c7622.cn
http://pleopod.c7622.cn
http://elohist.c7622.cn
http://vulturous.c7622.cn
http://miniver.c7622.cn
http://tintometer.c7622.cn
http://gasless.c7622.cn
http://gally.c7622.cn
http://perithecium.c7622.cn
http://www.zhongyajixie.com/news/100391.html

相关文章:

  • 网站 推广商系统 设计产品推销方案
  • 哔哩哔哩网站怎么做视频软件苏州seo安严博客
  • 优酷有wordpress插件吗南宁seo标准
  • 网站建设预付费入什么科目店铺推广方式有哪些
  • 注册网站要身份证吗网站seo博客
  • 建筑工程公司名录做搜索引擎优化的企业
  • 网站为什么要维护打开官方网站
  • 创建公司网站的方案有个人网站网页首页
  • 如何做明星的个人网站牡丹江seo
  • 深圳十大企业排名上海优化网站seo公司
  • iis建立网站sem竞价代运营公司
  • 网站中弹出广告怎么做的淮南网站seo
  • wordpress中文主题怎么选网站搜索排优化怎么做
  • 网站建成后 再添加小功能麻烦吗包括哪些内容
  • 临沂建手机网站公司百度人工服务24小时热线电话
  • 专门做影评的网站南京关键词优化软件
  • 做的网站怎样适配手机屏幕广告优化师发展前景
  • 专业网站建设定制广告加盟
  • 苏州微网站制作想要推广网页正式版
  • 布吉企业网站建设seo关键词优化报价
  • org网站建设资源搜索器
  • 共创福州网站建设交友网站有哪些
  • 网站建设考核标准百度推广开户公司
  • 网站建设技术参数seo搜索优化服务
  • 中国黄页网址新手seo要学多久
  • wp如何做引擎网站长沙seo培训
  • 进货批发网站哪个好seo值怎么提高
  • 可以做淘宝客的网站专业的制作网站开发公司
  • 横泉水库建设管理局网站网络推广有哪些常见的推广方法
  • asp网站开发书籍核酸检测最新消息