1010#include < iostream>
1111#include < memory>
1212
13- using combining::composite ::DuckCall;
14- using combining::composite ::Goose;
15- using combining::composite ::GooseAdapter;
16- using combining::composite ::IQuackable;
17- using combining::composite ::MallardDuck;
18- using combining::composite ::QuackCounter;
19- using combining::composite ::RedheadDuck;
20- using combining::composite ::RubberDuck;
13+ using combining::decorator ::DuckCall;
14+ using combining::decorator ::Goose;
15+ using combining::decorator ::GooseAdapter;
16+ using combining::decorator ::IQuackable;
17+ using combining::decorator ::MallardDuck;
18+ using combining::decorator ::QuackCounter;
19+ using combining::decorator ::RedheadDuck;
20+ using combining::decorator ::RubberDuck;
2121
2222void simulate (IQuackable* duck)
2323{
@@ -26,18 +26,18 @@ void simulate(IQuackable* duck)
2626
2727int main ()
2828{
29- MallardDuck mallardDuck;
30- RedheadDuck redheadDuck;
31- DuckCall duckCall;
32- RubberDuck rubberDuck;
29+ std::shared_ptr<IQuackable> mallardDuck = std::make_shared<QuackCounter>(std::make_shared<MallardDuck>()) ;
30+ std::shared_ptr<IQuackable> redheadDuck = std::make_shared<QuackCounter>(std::make_shared<RedheadDuck>()) ;
31+ std::shared_ptr<IQuackable> duckCall = std::make_shared<QuackCounter>(std::make_shared<DuckCall>()) ;
32+ std::shared_ptr<IQuackable> rubberDuck = std::make_shared<QuackCounter>(std::make_shared<RubberDuck>()) ;
3333 GooseAdapter gooseDuck{std::make_shared<Goose>()};
3434
3535 std::cout << " \n Duck Simulator: With Decorator" << ' \n ' ;
3636
37- simulate (& mallardDuck);
38- simulate (& redheadDuck);
39- simulate (& duckCall);
40- simulate (& rubberDuck);
37+ simulate (mallardDuck. get () );
38+ simulate (redheadDuck. get () );
39+ simulate (duckCall. get () );
40+ simulate (rubberDuck. get () );
4141 simulate (&gooseDuck);
4242
4343 std::cout << " The ducks quacked " << QuackCounter::getQuacks () << " times" << ' \n ' ;
0 commit comments