Beispiel #1
0
int main()
{
	Facade* test = new Facade();
	test->FacadeMethod();
	system("pause");
	return 0;
}
Beispiel #2
0
Facade* Facade::getInstance(std::string key)
{
    Facade* facade = Multiton<Facade>::instance(key);
    facade->initializeNotifier(key);
    facade->initializeFacade();
    return facade;
}
Beispiel #3
0
void test_facade()
{
	Facade* f = new Facade;
	f->OperationWrapper();

	delete f;
}
Beispiel #4
0
	Sender(const unsigned char* data, string ia, tpport_t port, uint32 tstamp,
			uint16 count) :

		packetsPerSecond(10) {

		Facade* facade = Facade::getInstance();
		SessionManager* session = facade->createClientSession(ia, port,
				new RecordDevice, new PlaybackDevice,
				"/home/ivocalado/workspace/streamadapt/policies/instance1.xml",
				0);

		TransportSession* sender = session->getTSession();
		uint32 timestamp = tstamp ? tstamp : 0;
		//
		//
		//
		string s = sender->getSession()->retrievePluginInformation(
				"CurrentRTPClockRate");
		istringstream s1(s);
		uint16 tstampInc = 0;
		s1 >> tstampInc;
		tstampInc /= packetsPerSecond;
		uint32 period = 1000 / packetsPerSecond;
		TimerPort::setTimer(period);
		for (int i = 0; i < count; i++) {
			uint32 tmp = timestamp + i * tstampInc;
			sender->getSession()->sendData(tmp, data,
					strlen((char *) data) + 1, &b);
			Thread::sleep(TimerPort::getTimer());
			TimerPort::incTimer(period);
		}
		session->endSession();
	}
int main() {
    Facade * facade = new Facade();

    facade->MethodA();
    facade->MethodB();

    return 0;
}
int main(int argc, char *argv[])
{
    Facade *f = new Facade();
    f->OperationWrapper();

    system("pause");
    return 0;
}
	void test_wg()
	{
		cout << "\n----外观模式----\n";
		//外观模式中, 外部只能看到Facade类, 且只能通过Facede类接口完成内部系统的逻辑
		Facade facade;
		facade.DoSomething();

	}
int main(int argc, char * argv[])
{
  Facade *facade = new Facade();
  facade->Method();
  delete facade;

  system("pause");
  return 0;
}
int main()
{
  Facade facade;
  facade.calc(30);
  facade.calc(36);
  facade.calc(2);

  return EXIT_SUCCESS;
}
int main()
{
	Facade *pFacade = new Facade();

	pFacade->MethodA();
	pFacade->MethodB();

	system("pause");
	return 0;
}
Beispiel #11
0
int main(void){
  cout<<"Facade Pattern Sample Start!!"<<endl;

  //ユーザが使用するのはfacadeクラスだけ
  Facade facade;
  //facadeの簡易的な関数を実行するだけで、クラスA,B,Cの複雑な処理を実施してくれる
  facade.Do();

  return 0;
}
Beispiel #12
0
int main()
{
	/*Create object of Facade*/
	Facade shapeMaker;

	/*Use this object to control the other object functionalties*/
	shapeMaker.drawCircle();
	shapeMaker.drawRectangle();
	shapeMaker.drawSquare();

    return 0;
}
//-----------------------------------------------------------------------
void DestoryContextCommand::_destroyContext(u2::Context* context)
{
    if (context == nullptr)
    {
        return;
    }

    // destroy children
    u2::Context::ContextMapIterator it = context->getChildIterator();
    while (it.hasMoreElements())
    {
        _destroyContext(it.getNext());
    }


    // destroy view component
    ViewComponent* pViewComp = ViewComponentManager::getSingletonPtr()->retrieveObjectByName(context->getViewCompName());
    if (pViewComp != nullptr)
    {
        //pViewComp->end();
        Facade* pFacade = FacadeManager::getSingletonPtr()->retrieveObjectByName(context->getFacadeName());
        if (pFacade != nullptr)
        {
            pFacade->removeViewComp(context->getViewCompName());
        }
        ViewComponentManager::getSingletonPtr()->destoryObject(pViewComp);
    }

    // destroy context
    u2::Context* pParent = context->getParent();
    if (pParent == nullptr)
    {
        pParent->removeChild(context);
    }
    ContextProxy* pContextProxy = getFacade().retrieveProxy<ContextProxy>(ON_Proxy_Context);
    pContextProxy->erase(context);
    ContextManager::getSingletonPtr()->destoryObject(context);
}
void MainWindow::testFacade()
{
    Facade *pFacade = new Facade();
    pFacade->operation();
}
 static void up(Facade& f)
 {
     f.up();
 }
 static void right(Facade& f)
 {
     f.right();
 }
 static void left(Facade& f)
 {
     f.left();
 }
 static typename Facade::size_type idx(Facade const& f)
 {
     return f.idx();
 }
 static typename Facade::size_type max_size_(Facade const& f)
 {
     return f.max_size_();
 }
 static bool is_root_(Facade const& f)
 {
     return f.is_root_();
 }
 static bool empty_(Facade const& f)
 {
     return f.empty_();
 }
Beispiel #22
0
int main() {
  std::cout << "==== start ====" << std::endl;
  Facade f = Facade();
  f.DoDomainLogic();
  std::cout << "==== end ====" << std::endl;
}
Beispiel #23
0
//适配器模式是在类已经设计好后实施
//桥接模式在设计类之前实施
//外观模式定义一个新接口
//适配器模式是复用原有的接口, 即适配器模式是使两个原有的接口协同工作, 而不是定义一个全新的接口
int main()
{
	//适配器模式:客户欲使用的功能与已有类Adaptee相同,但客户已知接口与Adaptee不同,
	//			 此时由于特殊原因无法修改Adaptee的接口,和客户使用接口的代码。
	//			 则创建一个适配接口的类Adapter,含有Adaptee的实例,接口声明为客户待使用的接口。
	//			 在Adapter实现中调用功能相同的Adaptee的方法
	Adapter a;
	Client c(&a);
	c.Do();


	//桥接模式:impl技法 抽象接口与实现分离,各自独立变化互不影响
	//			实现改变时不影响客户代码使用
	//			接口改变,功能不变时实现代码不需变化
	Abstraction abs;
	abs.Foo();
	abs.Bar();

	//组合模式:需求中是体现部分与整体层次的结构时,又希望用户可以忽略组合对象与单个对象的不同
	//		   统一地使用组合结构中的所有对象时
	//透明方式和安全方式
	PartA pa("PartA");
	PartB pb("PartB");
	CompanyA ca("rootCompany");
	ca.AddPart(&pa);
	ca.AddPart(&pb);
	ca.Display(1);

	//装饰模式:动态地给一个对象添加一些额外的额职责,就增加功能来说,装饰模式比生成子类更为灵活
	//优点:把每个要装饰的功能放在单独的类中,并让这个类包装它所要装饰的对象。因此,当需要执行特殊行为时,
	//客户代码就可以在运行时根据需要有选择地、按顺序地使用装饰功能包装对象。
	//有效地把类的核心职责和装饰功能区分开了,可以去除相关类中重复的装饰逻辑
	//装饰----当系统需要新功能的时候,是向旧的类中添加新的代码,例如:新的字段,新的方法和新的逻辑
	//这些新加的代码通常装饰了原有类的核心职责或主要行为
	ConcreteComponent cct;
	DecoratorShow(&cct);

	//外观模式:为子系统中的一组接口提供一个一致的界面,此模式定义了一个高层接口,这个接口使得这一子系统更加容易使用
	//完美体现依赖倒转, 迪米特法则
	//使用时机:
	//1.设计初期,不同的层分离,层与层之间建立外观Facade
	//2.开发阶段,子系统往往因为不断的重构演化而变得越来越复杂,增加外观可以提供一个简单的接口,减少它们之间的依赖.
	//3.维护阶段,为新系统开发一个外观类,来提供设计粗糙或高度复杂的遗留代码的比较清晰简单的接口,让新系统与Facade对象交互
	//			Facade对象与旧系统的遗留代码交互所有复杂的工作
	Facade facade;
	facade.Foo();
	facade.Bar();

	//享元模式:	如果一个应用程序使用了大量的对象,而大量的这些对象造成了很大的存储开销时就应该考虑使用;还有就是对象的大多数状态可以外部状态,
	//			如果删除对象的外部状态,那么可以用相对较少的共享对象取代很多组对象
	//例:.net中String; 休闲游戏中的棋子对象
	//缺点:使用享元模式需要维护一个记录了系统已有的所有享元的列表,本身需要耗费资源,也使系统更加复杂
	FlyweightFactory ff;
	auto f1 = ff.GetFlyweight("ABC");
	f1->Operation();
	auto f2 = ff.GetFlyweight("DEF");
	f2->Operation();
	auto f3 = ff.GetFlyweight("ABC");
	f3->Operation();

	int count = ff.GetInstanceCount();

	//代理模式:为其他对象提供一种代理以控制这个对象的访问
	//1.远程代理
	//2.虚代理
	//3.保护代理
	//4.智能指针
	//
}
Beispiel #24
0
int main()
{
    Facade* instance = Facade::Instance();
    instance->Operation();
    return 0;
}
Beispiel #25
0
 Facade* copyAndMultiplyBy(std::complex<double> const coefficient) const {
     Facade* x = this->copy();
     x->multiplyBy(coefficient);
     return x;
 }
Beispiel #26
0
int main(int argc, char *argv[])
{
	CSingleton *one = CSingleton::getInstance();	

	cout << "<<< Factory pattern >>>" << endl;
	Factory *fact = new DeriveFactory();
	Product *p1 = fact->createProduct();
	p1->display();

	AbstractFactory *abs1One = new Group1Factory();
	abs1One->createProductA();
	abs1One->createProductB();

	AbstractFactory *abs2One = new Group2Factory();
	abs2One->createProductA();
	abs2One->createProductB();

	Reciever *pRev = new Reciever();
	Command *pComm = new SubCommand(pRev);
	Invoke in(pComm);
	in.Action();

	Command *pComm2 = new SimpleCommand<Reciever>(pRev, &Reciever::Action);
	pComm2->act();
	cout << "<<< Facade pattern >>>" << endl;
	Facade *fa = new Facade();
	fa->operate();

	cout << "<<< Flyweight pattern >>>" << endl;
	FlyweightFactory *fwFactory = new FlyweightFactory();
	fwFactory->GetFlyweight("hello")->opt("world");
	fwFactory->GetFlyweight("haha")->opt("!!!");
	fwFactory->GetFlyweight("hello")->opt("world2");

	cout << "<<< Proxy pattern >>>" << endl;
	SubSubject *pSub = new SubSubject();
	Proxy *p2 = new Proxy(pSub);
	p2->request();

	cout << "<<< prototype pattern >>>" << endl;
	Prototype *prot = new SubPrototype();	
	Prototype *prot2 = prot->clone();

	cout << "<<< observer pattern >>>" << endl;
	OSubject *pOSub = new SubOSubject();
	ObserverA *pObA = new ObserverA();
	ObserverB *pObB = new ObserverB();
	pOSub->attach(pObA);
	pOSub->attach(pObB);
	pOSub->SetState("old");
	pOSub->notify();
	pOSub->SetState("new");
	pOSub->notify();
	
	cout << "<<< visitor pattern >>>" << endl;
	Visitor *pV = new SubVisitorA();
	Element *pE = new ElementA();
	pE->accept(pV);

	cout << "<<< state pattern >>>" << endl;
	State *pS = new StateA();
	Context *pSub3 = new Context(pS);
	pSub3->Operate();
	pSub3->Operate();
	pSub3->Operate();
	return 0;
}
Beispiel #27
0
///为子系统中的一组接口提供一个一致的界面, Facade模式定义了一个高层接口,这个接口使得这一子系统更加容易使用
///比如为点灯 冰箱 空调提供一个关闭电源的高层接口
///Façade 模式在高层提供了一个统一的接口,解耦了系统。设计模式中还有另一种模式 Mediator 也和 Façade 有类似的地方。但是 Mediator 主要目的是对象间的访问的解耦
void FacadeTest() {
    Facade* f = new Facade();
    f->OperationWrapper();
}
Beispiel #28
0
		Map::Map(const Facade & wf, size_type size, bool write) :
			m_size(simstd::min(wf.size(), size)), m_frame(check_frame(DEFAULT_FRAME)), m_map(CheckHandle(::CreateFileMapping(wf, nullptr, (write) ? PAGE_READWRITE : PAGE_READONLY,
					high_part_64(m_size), low_part_64(m_size), nullptr))),
			m_write(write) {
			}