Skip to content

Commit

Permalink
Wood duck can fly as a rocket due to dynamic properties change
Browse files Browse the repository at this point in the history
  • Loading branch information
Kudryashov Dmitrii committed Oct 31, 2021
1 parent b0c7f43 commit 73d047f
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions SimUDuck/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,13 @@ class FlyNoWay : public FlyBehavior {
}
};

class FlyRocketPowered : public FlyBehavior {
public:
void fly() override {
cout << "I’m flying with a rocket!\n";
}
};

class QuackBehavior {
public:
virtual void quack() = 0;
Expand Down Expand Up @@ -79,6 +86,10 @@ class Duck {

virtual void display() = 0;

void setFlyBehavior(FlyBehavior* fb) {
flyBehavior_ = move(unique_ptr<FlyBehavior>(fb));
}

private:
string name_;
unique_ptr<FlyBehavior> flyBehavior_;
Expand Down Expand Up @@ -136,6 +147,10 @@ int main() {
ducks.emplace_back(new RubberDuck("Mark"s));
ducks.emplace_back(new WoodDuck("Alice"s));

unique_ptr<Duck> super_wood_duck(new WoodDuck("SuperDuck"s));
super_wood_duck->setFlyBehavior(new FlyRocketPowered());
ducks.emplace_back(move(super_wood_duck));

for (const auto& duck : ducks) {
duck->getName();
duck->display();
Expand Down

0 comments on commit 73d047f

Please sign in to comment.