策略模式便是提前准备一组算法,并将每一个算法封装下去,促使她们可以交换(这里的核心便是算法的逻辑性抽象化,插口封装到一个类中,再根据委派的形式将详细的算法完成授权委托给详细的类来完成)
对称性加密速度更快加密互联网大数据块文档特性,加密密钥和解密密钥是一样的
非对称加密加密,加密速度比较慢、加密抗压强度高高的,安全系数特性,加密密钥和解密密钥不一样
#include<iostream>
using namespace std;
class Strategy
{
public:
virtual void crypy() = 0;
};
class AES :public Strategy
{
public:
virtual void crypy()
{
cout << \"AES加密算法 \" << endl;
}
};
class DES :public Strategy
{
public:
virtual void crypy()
{
cout << \" DES加密算法\" << endl;
}
};
class Context
{
public:
void setStrategy(Strategy *strategy)
{
this->strategy = strategy;
}
void myoperator()
{
strategy->crypy();
}
private:
Strategy *strategy;
};
void main()
{
//
DES *des = new DES;
des->crypy();
delete des;
Strategy*strategy = NULL;
strategy= new DES;
Context *context = new Context;
context->setStrategy(strategy);
context->myoperator();
delete strategy;
delete context;
system(\"pause\");
return;
}
中介公司者方式便是界定一个中介公司目标,未封装系列产品目标间的互动,终极者是每个目标不用表明的互相启用,进而使其耦合度疏松,并且可以单独的更改她们中间的互动
中介公司者问题抛出去
#include<iostream>
using namespace std;
#include\"string\"
class Person
{
public:
Person(string name, int sex, int condi)
{
m_name=name;
m_sex=sex;
m_condi = condi;
}
string getName()
{
return m_name;
}
int getSex()
{
return m_sex;
}
int getCondi()
{
return m_condi;
}
protected:
string m_name;
int m_sex;
int m_condi;
};
class Women :public Person
{
public:
Women(string name, int sex, int condi) :Person(name, sex, condi)
{
}
virtual void getParter(Person*p)
{
if (this->m_sex == p->getSex())
{
cout << \"我不是同性恋者..(这儿便是问题科学研究,没有一切情感颜色)\" << endl;
}
if (this->getCondi() == p->getCondi())
{
cout << this->getName() << \"和\" << p->getName() << \"最佳搭档\" << endl;
}
else
{
cout << this->getName() << \"和\" << p->getName() << \"bu配\" << endl;
}
}
};
class Man :public Person
{
public:
Man(string name, int sex, int condi) :Person(name, sex, condi)
{
}
virtual void getParter(Person*p)
{
if (this->m_sex == p->getSex())
{
cout << \"我不是同性恋者..(这儿便是问题科学研究,没有一切情感颜色)\" << endl;
}
if (this->getCondi() == p->getCondi())
{
cout << this->getName() << \"和\" << p->getName() << \"最佳搭档\" << endl;
}
else
{
cout << this->getName() << \"和\" << p->getName() << \"bu配\" << endl;
}
}
};
void main()
{
Person *xiaofang = new Women(\"小敏\", 2, 5);
Person *zhangsan = new Man(\"张三\", 1, 4);
Person *lisi = new Man(\"李四\", 2, 5);
xiaofang->getParter(zhangsan);
xiaofang->getParter(lisi);
system(\"pause\");
return;
}
中介公司者编码完成
#include<iostream>
using namespace std;
#include\"string\"
class Person
{
public:
Person(string name, int sex, int condi, Mediator*m)
{
m_name = name;
m_sex = sex;
m_condi = condi;
mediator = m;
}
string getName()
{
return m_name;
}
int getSex()
{
return m_sex;
}
int getCondi()
{
return m_condi;
}
protected:
string m_name;
int m_sex;
int m_condi;
Mediator mediator;
};
class Mediator//中介公司这的抽象化成员变量
{
public:
virtual void getParter() = 0;
void setMan(Person*pMan)
{
pMan = man;
}
void setWomen(Person*pMan)
{
pWomen = women;
}
public:
virtual void getParter()
{
if (pWomen->getSex() == pMan->getSex())
{
cout << \"我不是同性恋者..(这儿便是问题科学研究,没有一切情感颜色)\" << endl;
}
if (pWomen->getCondi() == pMan->getCondi())
{
cout << pWomen->getName() << \"和\" << pMan->getName() << \"最佳搭档\" << endl;
}
else
{
cout << pWomen->getName() << \"和\" << pMan->getName() << \"bu配\" << endl;
}
}
private:
Person *pWomen;
Person *pMan;
};
class Women :public Person
{
public:
Women(string name, int sex, int condi, Mediator*m) :Person(name, sex, condi,m)
{
}
public:
virtual void getParter(Person*p)
{
mediator->setMan(p);
mediator->setWomen(this);
mediator->getParter();
}
};
class Man :public Person
{
public:
Man(string name, int sex, int condi, Mediator*m) :Person(name, sex, condi,m)
{
}
public:
virtual void getParter(Person*p)
{
mediator->setMan(this);
mediator->setWomen(p);
mediator->getParter();
}
};
void main()
{
Mediator *m = new Mediator;
Person *xiaofang = new Women(\"小敏\", 2, 5,m);
Person *zhangsan = new Man(\"张三\", 1, 4,m);
Person *lisi = new Man(\"李四\", 2, 5,m);
xiaofang->getParter(zhangsan);
xiaofang->getParter(lisi);
system(\"pause\");
return;
}
版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容, 请发送邮件至 举报,一经查实,本站将立刻删除。