Exemple #1
0
void PlayWithDuck(Duck & duck)
{
	duck.Quack();
	duck.Dance();
	duck.Fly();
	DrawDuck(duck);
}
int main()
{
	Duck d;
	d.perforFly();
	d.setFlyBehavior(new FlyNoWays());
	d.perforFly();
	return 0;
}
int main() {
	
	Duck* obj = new RubberDuck(new FlyNoWay, new Quack);
	obj->display();
	obj->swim();
	obj->performFly();
	obj->performQuack();
}//end of main
Exemple #4
0
int main()
{
	Duck* mallard = new MallardDuck();
	mallard->performQuack();
	mallard->performFly();

	std::cout << "Hi" << std::endl;
	return 0;
}
int main(int argc, char* argv[])
{
	Duck* mallard = new MallardDuck();
	mallard->display();
	mallard->performFly();
	mallard->performQuack();
	Duck* model = new ModelDuck();
	model->display();
	model->performFly();
	model->setFlyBehavior(new FlyRocketPowered());
	model->performFly();
	return 0;
}
int main() {
	cout << "Adapter pattern" << endl; // prints !!!Hello World!!!

	Duck* dockPtr = new Duck();
	dockPtr->quackLikeADuck();

	Duck* mallardDockPointer = new MallardDuck();
	mallardDockPointer->quackLikeADuck();

	Turkey* turkeyPtr = new WildTurkey();
	//turkeyPtr->fly();
	//turkeyPtr->gobble();

	TurkeyAdapter* imitatesDucks = new TurkeyAdapter(turkeyPtr);

	testDuck(imitatesDucks);

	return 0;
}
Exemple #7
0
int main()
{
   //mallard duck
   Duck *mallard = new MallardDuck();
   mallard->display();
   mallard->performQuack();
   mallard->performFly();
   mallard->setFlyBehavior(new FlyWithRocket());
   mallard->performFly();

   delete mallard;

   //super duck
   Duck *super = new SuperDuck();
   super->display();
   //first quack and then fly
   super->performQuack();
   super->performFly();

   delete super;

   return 0;
}
int main()
{
	Duck *mallard = new MallardDuck();
	mallard->performFly();

	Duck *rubber = new RubberDuck();
	rubber->performFly();

	rubber->setFlyBehavior(new FlyRocketPowered());
	rubber->performFly();

	mallard->performQuack();
	rubber->performQuack();

	delete mallard;
	delete rubber;

	return 0;
}
int main()
{
	Duck *mallard = new MallardDuck();
	mallard->performFly();

	Duck *rubber = new RubberDuck();
	rubber->performFly();

	rubber->setFlyBehavior(new FlyRocketPowered()); // 실행 중 행위 변경
	rubber->performFly();

	return 0;
}
Exemple #10
0
int main()
{
    Duck *duck;
    RealDuck real; //真的会叫会飞的鸭子
    FakeDuck fake; //假的不会飞不会叫的鸭子

    duck = &real;   //动态绑定到真鸭子
    duck->performFly();
    duck->performQuack();

    duck = &fake;   //动态绑定到假鸭子
    duck->performFly();
    duck->performQuack();

    duck->setFlyBehavior(new FlyWithWind());    //运行时更改飞的属性
    duck->performFly();
    return 0;
}
Exemple #11
0
void main()
{
    FlyBehavior *pfWings = new FlyWithWings;
    FlyBehavior *pfNo = new FlyNoWay;
    FlyBehavior *pfRocket = new FlyWithRocket;

    Duck *pDuck = new MallardDuck(pfWings);
    pDuck->performFly();

    pDuck->setFlyBehavior(pfNo);
    pDuck->performFly();

    pDuck->setFlyBehavior(pfRocket);
    pDuck->performFly();
}
Exemple #12
0
void DrawDuck(Duck const& duck)
{
	duck.Display();
}
Exemple #13
0
// ----------------------- The main event -------------------------
int main()
{
    Duck *mallard = new MallardDuck();
    mallard->display();
    mallard->floatAround();
    mallard->performFly();
    mallard->performQuack();
    cout << endl;

    Duck *rubber = new RubberDuck();
    rubber->display();
    rubber->floatAround();
    rubber->performFly();
    rubber->performQuack();
    cout << endl;

    Duck *painted = new PaintedDuck();
    painted->display();
    painted->floatAround();
    painted->performFly();
    cout << endl;

    painted->setFlyBehaviour(new FlyWithRocket);
    painted->performFly();
    painted->performQuack();

    cout << endl;
    painted->setQuackBehaviour(new Quack);
    painted->performQuack();
    return 0;
}
int main() {
	Duck *d = &NormalDuck();
	d.perform_fly();
}
static inline void testDuck(Duck& duck) {
    duck.quack();
    duck.fly();
}
Exemple #16
0
Duck* Duck::create(DuckType type)
{
    Duck* duck = new Duck(type);
    duck->autorelease();
    return duck;
}